Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """Daemon vs. non-daemon processes.
  7. """
  8. #end_pymotw_header
  9.  
  10. import multiprocessing
  11. import time
  12. import sys
  13.  
  14. def daemon():
  15. name = multiprocessing.current_process().name
  16. print 'Starting:', name
  17. time.sleep(2)
  18. print 'Exiting :', name
  19.  
  20. def non_daemon():
  21. name = multiprocessing.current_process().name
  22. print 'Starting:', name
  23. print 'Exiting :', name
  24.  
  25. if __name__ == '__main__':
  26. d = multiprocessing.Process(name='daemon',
  27. target=daemon)
  28. d.daemon = True
  29.  
  30. n = multiprocessing.Process(name='non-daemon',
  31. target=non_daemon)
  32. n.daemon = False
  33.  
  34. d.start()
  35. time.sleep(1)
  36. n.start()
  37.  
  38. d.join()
  39. n.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement