diff options
author | Guido van Rossum <guido@python.org> | 1991-04-21 19:33:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-04-21 19:33:53 (GMT) |
commit | a31b9ccbbc66614b1026bdade5a9adec79912074 (patch) | |
tree | c453b7296e7803ed8dacc52758147b3f7507102e /Lib/sched.py | |
parent | fa0e726154f04ef32e9dec9c991e66ae7fec3f1d (diff) | |
download | cpython-a31b9ccbbc66614b1026bdade5a9adec79912074.zip cpython-a31b9ccbbc66614b1026bdade5a9adec79912074.tar.gz cpython-a31b9ccbbc66614b1026bdade5a9adec79912074.tar.bz2 |
Delay zero after successful action.
Diffstat (limited to 'Lib/sched.py')
-rw-r--r-- | Lib/sched.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/sched.py b/Lib/sched.py index b70a998..6abd251 100644 --- a/Lib/sched.py +++ b/Lib/sched.py @@ -11,8 +11,8 @@ # and millisleep from the built-in module time, or you can implement # simulated time by writing your own functions. This can also be # used to integrate scheduling with STDWIN events; the delay function -# is allowed to modify the queue. Time can be expressed -# as integers or floating point numbers, as long as it is consistent. +# is allowed to modify the queue. Time can be expressed as +# integers or floating point numbers, as long as it is consistent. # Events are specified by tuples (time, priority, action, argument). # As in UNIX, lower priority numbers mean higher priority; in this @@ -83,6 +83,11 @@ class scheduler(): # exceptions are not caught but the scheduler's state # remains well-defined so run() may be called again. # + # A questionably hack is added to allow other threads to run: + # just after an event is executed, a delay of 0 is executed, + # to avoid monopolizing the CPU when other threads are also + # runnable. + # def run(self): q = self.queue while q: @@ -93,4 +98,5 @@ class scheduler(): else: del q[0] void = action(argument) + self.delayfunc(0) # Let other threads run # |