python - pausing a thread from a function and resuming it -
python - pausing a thread from a function and resuming it -
i have many threads in programme written below. wanted pause threads when 1 particular function called thread, , should resume after function execution of function finished or after delay of 1 second. illustration in code below, pause threads switch1 , switch2 when switch3 beingness executed, , resume these threads after switch2 finishes execution or after elay of 1 second.
can please allow me know how implement in code below ?
def switch1(): if (buttonpressed ==1): print 1 def switch2(): if (buttonpressed1 ==1): switch3() print 1 def switch3(): if (buttonpressed2 ==1): print 1 def main(): switch1thread=threading.thread(target=switch1) switch2thread=threading.thread(target=switch2) switch1thread.start() switch2thread.start()
you can not pause , resume threads without cooperation of thread itself. thread want pause or resume can pause , resume checking flags. e.g. can set flag before executing switch3
. switch2
, switch1
pause if flag set.
python multithreading
Comments
Post a Comment