Advertisement
nigaky

multiprocessing sample

Dec 22nd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from multiprocessing import Process
  4.  
  5. class MyProcess(Process):
  6.     def __init__(self, msg):
  7.         super(MyProcess, self).__init__()
  8.         self.msg = msg
  9.  
  10.     def run(self):
  11.         print self.msg
  12.  
  13. def f(msg):
  14.     print msg
  15.  
  16. def main():
  17.     p = Process(target=f, args = ("I'm child", ))
  18.     p.start()
  19.     p.join()
  20.  
  21.     # using MyProcess class
  22.     p = MyProcess("I'm child")
  23.     p.start()
  24.     p.join()
  25.  
  26. if __name__ == '__main__':
  27.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement