Issue #16640: Run less code under a lock in sched module.
This commit is contained in:
parent
1147f82438
commit
d07db96ab6
11
Lib/sched.py
11
Lib/sched.py
|
@ -71,10 +71,10 @@ class scheduler:
|
||||||
"""
|
"""
|
||||||
if kwargs is _sentinel:
|
if kwargs is _sentinel:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
event = Event(time, priority, action, argument, kwargs)
|
||||||
with self._lock:
|
with self._lock:
|
||||||
event = Event(time, priority, action, argument, kwargs)
|
|
||||||
heapq.heappush(self._queue, event)
|
heapq.heappush(self._queue, event)
|
||||||
return event # The ID
|
return event # The ID
|
||||||
|
|
||||||
def enter(self, delay, priority, action, argument=(), kwargs=_sentinel):
|
def enter(self, delay, priority, action, argument=(), kwargs=_sentinel):
|
||||||
"""A variant that specifies the time as a relative time.
|
"""A variant that specifies the time as a relative time.
|
||||||
|
@ -82,9 +82,8 @@ class scheduler:
|
||||||
This is actually the more commonly used interface.
|
This is actually the more commonly used interface.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with self._lock:
|
time = self.timefunc() + delay
|
||||||
time = self.timefunc() + delay
|
return self.enterabs(time, priority, action, argument, kwargs)
|
||||||
return self.enterabs(time, priority, action, argument, kwargs)
|
|
||||||
|
|
||||||
def cancel(self, event):
|
def cancel(self, event):
|
||||||
"""Remove an event from the queue.
|
"""Remove an event from the queue.
|
||||||
|
@ -165,4 +164,4 @@ class scheduler:
|
||||||
# the actual order they would be retrieved.
|
# the actual order they would be retrieved.
|
||||||
with self._lock:
|
with self._lock:
|
||||||
events = self._queue[:]
|
events = self._queue[:]
|
||||||
return map(heapq.heappop, [events]*len(events))
|
return map(heapq.heappop, [events]*len(events))
|
||||||
|
|
|
@ -200,6 +200,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #16640: Run less code under a lock in sched module.
|
||||||
|
|
||||||
- Issue #16165: Fix sched.scheduler.run() method was block a scheduler for
|
- Issue #16165: Fix sched.scheduler.run() method was block a scheduler for
|
||||||
other threads.
|
other threads.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue