[Twisted-Python] Forking after starting AsyncioSelectorReactor: Supported?

David Foster davidfstr at gmail.com
Mon Aug 27 22:12:57 MDT 2018


Hi Twisted list!

I have a library that is attempting to start an AsyncioSelectorReactor, 
fork the process, and then open a network socket on macOS. When the 
network socket is opened, Twisted throws an [Errno 9] "Bad file 
descriptor" exception at me. I get no such exception on Ubuntu.

If I change the sequence from:
     setup_reactor('AsyncioSelectorReactor')
     fork_and_continue_in_child()
     run_server()
to:
     fork_and_continue_in_child()             # fork first
     setup_reactor('AsyncioSelectorReactor')
     run_server()
Then everything works okay.

Also if I use SelectReactor rather than AsyncioSelectorReactor then it 
doesn't matter which order I fork in.

So my question is, does Twisted support being forked after starting a 
reactor or not?

-- 
David Foster | Seattle, WA, USA


P.S. For more details see this Django Channels thread: 
https://github.com/django/channels/issues/962#issuecomment-414103367



More information about the Twisted-Python mailing list