Skip to content

Instantly share code, notes, and snippets.

@muzhig
Created May 5, 2014 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muzhig/3c84cc41f0c131760ac5 to your computer and use it in GitHub Desktop.
Save muzhig/3c84cc41f0c131760ac5 to your computer and use it in GitHub Desktop.
twisted process fork
@classmethod
def start(cls, port=8080, extra_workers=0):
reactor.listenTCP(port, server.Site(cls()))
for i in range(extra_workers):
pid = os.fork()
if pid == 0:
# Proceed immediately onward in the children.
# The parent will continue the for loop.
break
else:
print 'Spawned child:', pid
else:
print 'Parent', os.getpid()
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment