[Twisted-Python] _twistd_unix.py / daemonize() / OSX / USING_FORK_WITHOUT_EXEC_IS_NOT_SUPPORTED_BY_FILE_MANAGER
glyph at twistedmatrix.com
Wed Oct 13 16:46:35 EDT 2010
On Oct 13, 2010, at 1:20 PM, James Y Knight wrote:
>> Here's a compact version. The script uses OSX' Quartz to create and manipulate images. Twisted is used to wrap it as a webserver, images are served. More pointers on how to start and use it in the script itself.
> You need to avoid using or importing any OSX APIs until after the daemonization has occurred. Unfortunately, twisted executes the entire script file before daemonizing. [that's unfortunate for other reasons besides this, too]
To the extent that this is an intentional decision (it's at least half accidents of implementation) it's an attempt to allow twistd to actually display an error on the console if there is a serious error starting up, i.e. your plugin is not syntactically valid Python and it's just going to exit.
While I remember agreeing that it's unfortunate, I can't actually recall any issues with executing the script before forking. Do we have tickets for them? Can you describe a couple?
If we are going to change this behavior, we should make twistd do something more correct, and optionally allow it to report startup errors to the console after it's forked, even if those errors don't necessarily crash it during startup. This isn't rocket science, inheriting file descriptors and delaying exit are all pretty easy.
> Here's a corrected version of your script which works properly. It defers importing Quartz until the reactor is running, by moving it into a function called by reactor.callWhenRunning().
Thanks for this, I'm sure that other folks will find it useful. I'm a bit surprised it's not more of a FAQ!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python