Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import threading
  2. from threading import Thread
  3. from threading import Event
  4. import queue
  5.  
  6. sem=threading.Semaphore()
  7.  
  8. def setup_for_long_running_task(self):
  9. print("start")
  10. self.f1.config(cursor="wait") # Set the cursor to busy
  11. sem.acquire()
  12.  
  13. return_que = queue.Queue(1)
  14. workThread = Thread(target=lambda q, w_self:
  15. q.put(self.long_running_task()),
  16. args=return_que)
  17. workThread.start()
  18.  
  19. self.f1.after(5000,use_results_of_long_running_task(self,workThread,return_que)) # 500ms is half a second
  20. sem.release()
  21. print("stop")
  22.  
  23. def long_running_task(self):
  24.  
  25. Event().wait(3.0) # Simulate long running task
  26.  
  27. def use_results_of_long_running_task(self, workThread,return_que):
  28. ThreadRunning = 1
  29. while ThreadRunning:
  30. Event().wait(0.1) # this is set to .1 seconds. Adjust for your process
  31. ThreadRunning = workThread.is_alive()
  32.  
  33. while not return_que.empty():
  34. return_list = return_que.get()
  35.  
  36. self.f1.config(cursor="")
  37.  
  38. TypeError: <lambda>() argument after * must be an iterable, not Queue.
  39.  
  40. Exception in thread Thread-7:
  41. Traceback (most recent call last):
  42. File "C:ProgramDataAnaconda3libthreading.py", line 917, in
  43. _bootstrap_inner
  44. self.run()
  45. File "C:ProgramDataAnaconda3libthreading.py", line 865, in run
  46. self._target(*self._args, **self._kwargs)
  47. TypeError: <lambda>() argument after * must be an iterable, not Queue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement