I have a python schedule from sched
module that I want to execute in a separate thread while being able to stop it at any moment. I looked the threading module
but do not know which is the best approach to implement this.
example of the schedule:
>>> s.run()
one
two
three
end
example of the schedule in a thread:
>>> t = threading.Thread(target = s.run)
>>> t.start()
one
two
>>> print("ok")
ok
three
end
>>>
wanted result:
>>> u = stoppable_schedule(s.run)
>>> u.start()
>>>
one
two
>>> u.stop()
"schedule stopped"