ability to SIGINT/SIGTERM process (and be sure that any tasks are finished)
This commit is contained in:
parent
c5fef77bc8
commit
72e70e2ec6
1 changed files with 17 additions and 1 deletions
|
|
@ -51,11 +51,27 @@ class Scheduler(IScheduler):
|
||||||
return self.count
|
return self.count
|
||||||
|
|
||||||
def repeat(self, interval, function, *args):
|
def repeat(self, interval, function, *args):
|
||||||
|
if self.stop_event.isSet():
|
||||||
|
return
|
||||||
|
|
||||||
function(*args)
|
function(*args)
|
||||||
return self.schedule(interval, self._repeated_cb, interval, function, args)
|
return self.schedule(interval, self._repeated_cb, interval, function, args)
|
||||||
|
|
||||||
|
def _wait_to_stop(self):
|
||||||
|
self.want_stop()
|
||||||
|
for e in self.queue.itervalues():
|
||||||
|
e.cancel()
|
||||||
|
e.join()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.stop_event.wait()
|
try:
|
||||||
|
while 1:
|
||||||
|
self.stop_event.wait(0.1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self._wait_to_stop()
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
self._wait_to_stop()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def want_stop(self):
|
def want_stop(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue