Title: Implement os.fork() in Jython
Type: rfe Severity: normal
Components: Library Versions: Jython 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, teeohhem, zyasoft
Priority: low Keywords: RFE, twisted

Created on 2015-12-08.16:26:52 by teeohhem, last changed 2018-03-14.08:36:35 by jeff.allen.

msg10517 (view) Author: Tom Alexander (teeohhem) Date: 2015-12-08.16:26:52
Jython should implement os.fork() for even better Twisted support. Now that Jython 2.7.1 will include os.pipe(), many Twisted tests and code branches will now fail because it gets further in the process where os.fork() is eventually called. Perhaps we should consider using java subprocesses for this behavior.
msg10525 (view) Author: Jim Baker (zyasoft) Date: 2015-12-09.01:48:29
This has been a major wish list item for a while on the JVM; but see this in the corresponding JRuby project:

"JRuby doesn't implement fork() on any platform, including those where fork() is available in MRI. This is due to the fact that most JVMs cannot be safely forked."

For such purposes, Jython should be considered to be much like Python on Windows - no fork available. Subprocess is often, but not always, the same - think of daemonization, inherited file handles, etc.
msg10539 (view) Author: Tom Alexander (teeohhem) Date: 2015-12-16.16:18:29
Yeah I can certainly understand the reasoning for not implementing this. Unfortunately, this has a major impact on compatibility with Twisted and running a process as a service or daemon. Any suggestions on where to go from here?
msg10540 (view) Author: Jim Baker (zyasoft) Date: 2015-12-16.19:11:02
Besides some minor testing usage, Twisted uses `os.fork` for two purposes:

1. Daemonization support. For Java, we can do this a number of ways:

   a. Cassandra, as one example, simply closes stderr and stdout; see

            if (System.getProperty("cassandra-foreground") == null)

Note this doesn't actually daemonize anything; to do that, you need to use something like Debian's `start-stop-daemon` command, which is used by the DataStax init.d scripts.

    b. Various other good starting points exist for Linux. I found this blog post helpful:, which then points at the systemd man pages. Now that major distros have standardized on it, systemd especially works well and systemd can manage the complexity of daemonization. In other words, no worries about its former competitor, upstart.

    c. Apache Commons, specifically, using either jsvc for Unix-like systems or procrun for Windows to get the equivalent idea on that architecture. Tomcat uses this approach; see

2. Process building in `twisted.internet.process`. So this is really akin to what `subprocess` does, but looks like with more control. Perhaps it's something we can get at a Jython-specific equivalent using Java Native Runtime with, so long as we are on Unix-like systems.

Most likely the resolution of this bug is docs on the Jython wiki re daemonization; and possibly enhanced support for process building as part of a Jython-specific reactor.
msg11795 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-14.08:36:34
Tagging, and setting priority low as we appear unlikely to implement os.fork() as current title, while sympathetic to the objective behind it.
Date User Action Args
2018-03-14 08:36:35jeff.allensetkeywords: + twisted, RFE
priority: low
type: behaviour -> rfe
messages: + msg11795
nosy: + jeff.allen
2015-12-16 19:11:03zyasoftsetmessages: + msg10540
2015-12-16 16:18:30teeohhemsetmessages: + msg10539
2015-12-09 01:48:30zyasoftsetnosy: + zyasoft
messages: + msg10525
2015-12-08 16:26:52teeohhemcreate