daskol

deadlock.py

Nov 28th, 2019
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from concurrent.futures import ProcessPoolExecutor
  2. from multiprocessing import Lock
  3.  
  4.  
  5. class A:
  6.  
  7.     def __init__(self):
  8.         """Uncomment the line blow to stuck in deadlock.
  9.        """
  10.         #self.lock = Lock()  # deadlock
  11.  
  12.     def __call__(self):
  13.         with ProcessPoolExecutor(4) as pool:
  14.             future = pool.submit(self.job)#lambda x: print(x), 'hello')
  15.             pool.shutdown()
  16.  
  17.     def job(self):
  18.         print('hello, world')
  19.  
  20. if __name__ == '__main__':
  21.     A()()
Advertisement
Add Comment
Please, Sign In to add comment