summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/sched.py
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-04-18 12:39:32 +0300
committershadchin <[email protected]>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Lib/sched.py
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Lib/sched.py')
-rw-r--r--contrib/tools/python3/src/Lib/sched.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/contrib/tools/python3/src/Lib/sched.py b/contrib/tools/python3/src/Lib/sched.py
index ff87874a3a4..14613cf2987 100644
--- a/contrib/tools/python3/src/Lib/sched.py
+++ b/contrib/tools/python3/src/Lib/sched.py
@@ -26,23 +26,19 @@ has another way to reference private data (besides global variables).
import time
import heapq
from collections import namedtuple
+from itertools import count
import threading
from time import monotonic as _time
__all__ = ["scheduler"]
-class Event(namedtuple('Event', 'time, priority, action, argument, kwargs')):
- __slots__ = []
- def __eq__(s, o): return (s.time, s.priority) == (o.time, o.priority)
- def __lt__(s, o): return (s.time, s.priority) < (o.time, o.priority)
- def __le__(s, o): return (s.time, s.priority) <= (o.time, o.priority)
- def __gt__(s, o): return (s.time, s.priority) > (o.time, o.priority)
- def __ge__(s, o): return (s.time, s.priority) >= (o.time, o.priority)
-
+Event = namedtuple('Event', 'time, priority, sequence, action, argument, kwargs')
Event.time.__doc__ = ('''Numeric type compatible with the return value of the
timefunc function passed to the constructor.''')
Event.priority.__doc__ = ('''Events scheduled for the same time will be executed
in the order of their priority.''')
+Event.sequence.__doc__ = ('''A continually increasing sequence number that
+ separates events if time and priority are equal.''')
Event.action.__doc__ = ('''Executing the event means executing
action(*argument, **kwargs)''')
Event.argument.__doc__ = ('''argument is a sequence holding the positional
@@ -61,6 +57,7 @@ class scheduler:
self._lock = threading.RLock()
self.timefunc = timefunc
self.delayfunc = delayfunc
+ self._sequence_generator = count()
def enterabs(self, time, priority, action, argument=(), kwargs=_sentinel):
"""Enter a new event in the queue at an absolute time.
@@ -71,8 +68,10 @@ class scheduler:
"""
if kwargs is _sentinel:
kwargs = {}
- event = Event(time, priority, action, argument, kwargs)
+
with self._lock:
+ event = Event(time, priority, next(self._sequence_generator),
+ action, argument, kwargs)
heapq.heappush(self._queue, event)
return event # The ID
@@ -136,7 +135,8 @@ class scheduler:
with lock:
if not q:
break
- time, priority, action, argument, kwargs = q[0]
+ (time, priority, sequence, action,
+ argument, kwargs) = q[0]
now = timefunc()
if time > now:
delay = True