Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13780] Crash when using Process waitUntilExit on background thread in Windows #3967

Closed
swift-ci opened this issue Oct 26, 2020 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13780
Radar None
Original Reporter alex_taffe (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

compnerd.org Swift version 5.3-dev (LLVM b6c965e56f7a3c6, Swift 789ada59f316f84)
Windows 10 Pro Version 2004 Build 19041.572

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Windows
Assignee None
Priority Medium

md5: 401fa1b8ecbf06c995206676ce540660

Issue Description:

I have code that is similar to the following:

import Foundation
func runTask() -> Process? {
    let task = Process()
    task.arguments = ["--version"]

    if #os(Windows)
    task.executableURL = URL(fileURLWithPath: "C:/Program Files (x86)/Microsoft Visual Studio/Python37_64/python.exe")
    #else
    task.executableURL = URL(fileURLWithPath: "/usr/bin/python3")

    do {
        try task.run()
    } catch {
        return nil
    }

    DispatchQueue.global(qos: .utility).async {
        task.waitUntilExit()
        //do cleanup
    }

    return task
}
runTask()

On macOS this code runs fine. On Windows, the program immediately terminates with no error. Checking errorlevel just gives a nondescript 1073741819 (Google seems to indicate File System error). Oddly enough, changing async to sync causes the problem to go away and so does placing the waitUntilExit on the main thread (both of which are obviously a problem because it delays the return)

@compnerd
Copy link
Collaborator

compnerd commented Nov 2, 2020

The "nondescript" error is actually indicating the real issue - the path does not exist. At least for my default installation of Visual Studio, it is, in fact, correct. The Python interpreter by default is installed to C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe and your path does not seem correct (ignoring the obvious issues with the condition around the code). Fixing the path seems to resolve the issue for me. I suspect the hang in the changed case was due to a bug in Foundation's RunLoop that has since been fixed by @lxbndr.

I'm going to mark this as invalid for now, however, if you find that adjusting the path does not fix the issue, please re-open the issue.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 2, 2020

Comment by Alex Taffe (JIRA)

@compnerd I think the path to python is correct, if I totally change it to something wrong, it gives me a file not found error from Swift itself rather than immediately terminating. But if it’s just the RunLoop issue, I’ll try it again on a newer build.*

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants