Advertisement
DeaD_EyE

blocking_single_task

May 16th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import datetime
  2. import time
  3.  
  4.  
  5. def task(target_time, function, *args, **kwargs):
  6.     while True:
  7.         if datetime.datetime.now() > target_time:
  8.             return function(*args, **kwargs)
  9.         time.sleep(1)
  10.  
  11. def worker(programm):
  12.     print('Calling', programm)
  13.     return programm.upper()
  14.  
  15.  
  16. target_time = datetime.datetime.now() + datetime.timedelta(minutes=1)
  17. print('Starting task')
  18. result = task(target_time, worker, programm='Test123')
  19. # calling task blocks until the target time has been reached.
  20. print('Task finished')
  21. print('Result:', result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement