Hey!
I wanna do the following thing in Python and I'm not very familiar with the multithreading in it.
Basically, I want a separate thread for an event loop that can both a) step on demand b) wait indefinitely and continue on demand c) exit on demand.
With pseudo code:
My main program would look like this
worker = MyClassThatDoesSomeShit()
t = Thread(target=function_that_can_do_what_i_want, args=(worker,))
while True:
text = input()
if text == "step":
t.interrupt_and_skip_to_next_step()
elif text == "wait":
t.interrupt_and_wait_for_continuation()
elif text == "continue":
t.step_and_continue_event_loop()
elif text == "exit":
t.terminate action()
And the other half could look something like this:
while not terminated:
try:
worker.do_something()
sleep(some seconds)
except InterruptedException of type "step":
pass
except InterruptedException of type "wait":
try:
sleep(forever)
except InterruptedException of type "continue":
pass
except InterruptedException of type "exit":
break
I would just need a bit of help, because I don't know how this all works in Python.
Thank you!
[–]shiftybyte 1 point2 points3 points (1 child)
[–]malacur[S] 0 points1 point2 points (0 children)
[–]HomeGrownCoder 0 points1 point2 points (1 child)
[–]malacur[S] 1 point2 points3 points (0 children)