Skip to content

Instantly share code, notes, and snippets.

@zed
Created March 13, 2014 10:54
Show Gist options
  • Select an option

  • Save zed/9526217 to your computer and use it in GitHub Desktop.

Select an option

Save zed/9526217 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Show that a daemonic child process may have multiple threads."""
import multiprocessing
import threading
def child_process():
# start a thread
threading.Thread(target=child_thread).start()
# show that we can't have grandchildren processes
try:
multiprocessing.Process().start()
except AssertionError:
pass
else:
assert 0
def child_thread():
print("a thread in a daemonic child process")
if __name__=="__main__":
# start daemonic child process
p = multiprocessing.Process(target=child_process)
p.daemon = True
p.start()
#
p.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment