Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import sys
  2. from multiprocessing import Pool, Lock
  3.  
  4. class ParentApp():
  5.     mutex=Lock()
  6.     def report(self,msg):
  7.         with ParentApp.mutex:
  8.             sys.stdout.write(msg)
  9.  
  10. class ChildApp1(ParentApp):
  11.     def print_report(self):
  12.         for i in xrange(100):
  13.             ParentApp.report(self, 'BLABLA')
  14.  
  15.  
  16. class ChildApp2(ParentApp):
  17.     def print_report(self):
  18.         for i in xrange(100):
  19.             ParentApp.report(self, 'TESTTEST')
  20.  
  21. def runnable(app):
  22.     app.print_report()
  23.  
  24. def main():
  25.     app=[]
  26.     app.append(ChildApp1())
  27.     app.append(ChildApp2())
  28.  
  29.     pool = Pool(len(apps))
  30.     pool.map(runnable, apps)
  31.  
  32.     exit(0)
  33.  
  34. if __name__ == '__main__':
  35.     sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement