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

Avoids hung subprocess on macOS 10.12.4 when running a background task #112

Conversation

idpaterson
Copy link
Contributor

As discussed in #111 there is a problem on macOS 10.12.4 with running a subprocess from a double-forked daemon. Alfred-Workflow follows the classic recommendation for how to do this in Python so unless it is specific to how the Alfred app runs the workflow the problem may affect other python code as well.

This workaround is not predicated on the OS version. If the immediate exit of the parent process is essential to prevent zombie processes and other issues related to forking only once then this may introduce a regression.

The unit tests work fine in 10.12.4 so I think this may be related to how Alfred runs the workflow.

@idpaterson
Copy link
Contributor Author

Pressing pause on this for a moment, deploying the workaround in my own workflow did not fix the problem.

@deanishe
Copy link
Owner

deploying the workaround in my own workflow did not fix the problem

Bugger 😞

You could try removing the forks and using nohup or plain subprocess.Popen instead. The child process must disconnect from IO streams, however, as Alfred doesn't consider a script finished till it closes STDOUT and STDERR.

With native Mac apps, you should always follow a fork with an exec. I'm not sure if that applies to the UNIX layer, however.

@idpaterson
Copy link
Contributor Author

So glad you found it, well done!

@idpaterson idpaterson closed this Apr 1, 2017
@deanishe
Copy link
Owner

deanishe commented Apr 1, 2017

I think I did. I couldn't get the updated code to hang in 100+ tries across multiple workflows, at any rate.

All I did was compare the code with python-daemon. The use of os._exit() rather than sys.exit() was the only substantial difference, so I tried that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants