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.08s 11580KB
stdin
Standard input is empty
stdout
main line
module name: __main__
parent process: 23657
process id: 23658
function f
module name: __main__
parent process: 23658
process id: 23673
hello bob
[]
8