Changes between and of Initial VersionVersion 6Ticket #2535


Ignore:
Timestamp:
03/13/2010 11:25:24 PM (4 years ago)
Author:
glyph
Comment:

subprocess and popen aren't actually users of SIGCHLD, and as of #733 I don't think we actually conflict with them any more. Updating the summary and description to reflect the actual problem.

I don't think I'm actually interested in attempting this and I don't think it's too high priority, now that the majority of use-cases have been addressed.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2535

    • Property Priority changed from normal to low
    • Property Owner changed from glyph to exarkun
    • Property Summary changed from Allow Twisted to work without SIGCHLD on posix to Allow Twisted to work without interfering with libraries which use SIGCHLD on posix
  • Ticket #2535 – Description

    initial v6  
    1 Twisted currently needs to install a SIGCHLD handler for `reactor.spawnProcess` to work reliably.  This is problematic when Twisted is used with other libraries that depend on SIGCHLD (e.g. the standard library's subprocess module depends on SIGCHLD being left as SIG_DFL, otherwise it can get EINTR at unexpected times).  Hence the reactor can be run with the `installSignalHandlers=False` flag, but then reactor.spawnProcess isn't reliable. 
     1Twisted currently needs to install a SIGCHLD handler for `reactor.spawnProcess` to work reliably.  This is problematic when Twisted is used with other libraries that depend on handling SIGCHLD in their own way.  Currently, the reactor can be run with the `installSignalHandlers=False` flag to cooperate with such libraries, but then reactor.spawnProcess isn't reliable. 
    22 
    3 However, when run with `installSignalHandlers=False` Twisted could use a different strategy for notifications of subprocess termination.  `spawnProcess` could first fork a process that keeps a single file descriptor back to the parent open, and then forks the child that the caller of `spawnProcess` requested.  Then first subprocess could simply do: 
     3There are a couple of ways to work around this. 
    44 
    5 {{{ 
     5  1. When run with `installSignalHandlers=False` Twisted could use a different strategy for notifications of subprocess termination.  `spawnProcess` could first fork a process that keeps a single file descriptor back to the parent open, and then forks the child that the caller of `spawnProcess` requested.  Then first subprocess could simply do: 
     6 
     7  {{{ 
    68    pid = os.fork() 
    79    if pid: 
     
    1012       os.close(fd) 
    1113       os._exit() 
    12 }}} 
     14  }}} 
    1315 
    14 i.e. `wait` for the child process to finish, and then let the original process know the return value and exit.  The original process would know that the subprocess was done when it saw the fd get closed, and would know what the return value was. 
     16  i.e. `wait` for the child process to finish, and then let the original process know the return value and exit.  The original process would know that the subprocess was done when it saw the fd get closed, and would know what the return value was. 
    1517 
    16 It's ugly, but it might be better than nothing. 
     18  This does come at the unfortunate cost of having an additional process (an additional Python process, even!) per running subprocess, which is not insubstantial.  However, it is only in a fairly unusual case that you'd need it. 
     19 
     20  2. Another option is to repeatedly poll processes, at a timed interval, to see if they've exited yet.  Since most processes end up being either very short or very long running, we could probably come up with an heuristic for calculating the next polling interval that wouldn't be ''too'' inefficient. 
     21 
     22  3. Apparently some reactors (kqueue?  epoll?  iocp maybe?) may be able to specifically identify process-exited events independent of signals; this may be preferable to listening to SIGCHLD even if we don't need to cooperate with other software which uses it.  (Someone else please fill this in, since I'm not familiar with these APIs.) 
     23