fork download
  1. import multiprocessing
  2.  
  3. from multiprocessing import Process
  4. import os
  5.  
  6. def info(title):
  7. print(title)
  8. print('module name:', __name__)
  9. if hasattr(os, 'getppid'): # only available on Unix
  10. print('parent process:', os.getppid())
  11. print('process id:', os.getpid())
  12.  
  13. def f(name):
  14. info('function f')
  15. print('hello', name)
  16.  
  17. if __name__ == '__main__':
  18. info('main line')
  19. p = Process(target=f, args=('bob',))
  20. p.start()
  21. p.join()
  22. print(multiprocessing.active_children())
  23. print(multiprocessing.cpu_count())
Success #stdin #stdout 0.02s 8176KB
stdin
Standard input is empty
stdout
main line
('module name:', '__main__')
('parent process:', 24484)
('process id:', 24485)
function f
('module name:', '__main__')
('parent process:', 24485)
('process id:', 24514)
('hello', 'bob')
[]
8