aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/reactor.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-03-31 20:48:29 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-04-01 12:26:24 -0400
commit565861f680210ef6f3c13a375d3829ee7b319042 (patch)
tree80d32689301c01a71337182d18397efef8244282 /klippy/reactor.py
parent7c991399ac2d411a3cf9fe419f64815f32673bd2 (diff)
downloadkutter-565861f680210ef6f3c13a375d3829ee7b319042.tar.gz
kutter-565861f680210ef6f3c13a375d3829ee7b319042.tar.xz
kutter-565861f680210ef6f3c13a375d3829ee7b319042.zip
reactor: Support pause() command even when the reactor is not running
If the reactor isn't running then implement pause using the system sleep command. This simplifies the users of pause(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/reactor.py')
-rw-r--r--klippy/reactor.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/klippy/reactor.py b/klippy/reactor.py
index 1fd8426a..65536616 100644
--- a/klippy/reactor.py
+++ b/klippy/reactor.py
@@ -3,7 +3,7 @@
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import select, math
+import select, math, time
import greenlet
import chelper
@@ -71,9 +71,17 @@ class SelectReactor:
return 0.
return min(1., max(.001, self._next_timer - self.monotonic()))
# Greenlets
+ def _sys_pause(self, waketime):
+ # Pause using system sleep for when reactor not running
+ delay = waketime - self.monotonic()
+ if delay > 0.:
+ time.sleep(delay)
+ return self.monotonic()
def pause(self, waketime):
g = greenlet.getcurrent()
if g is not self._g_dispatch:
+ if self._g_dispatch is None:
+ return self._sys_pause(waketime)
return self._g_dispatch.switch(waketime)
if self._greenlets:
g_next = self._greenlets.pop()