summaryrefslogtreecommitdiffstats
path: root/Lib/sched.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2012-12-29 19:46:37 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2012-12-29 19:46:37 (GMT)
commitd07db96ab6942acef2e95194043d6d30ac48604e (patch)
treeb9c1ebe46e0b43c9d33c85c7c12d2f75cf2fa1f0 /Lib/sched.py
parent1147f824388354ec9870da238141b4d33bba8210 (diff)
downloadcpython-d07db96ab6942acef2e95194043d6d30ac48604e.zip
cpython-d07db96ab6942acef2e95194043d6d30ac48604e.tar.gz
cpython-d07db96ab6942acef2e95194043d6d30ac48604e.tar.bz2
Issue #16640: Run less code under a lock in sched module.
Diffstat (limited to 'Lib/sched.py')
-rw-r--r--Lib/sched.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/sched.py b/Lib/sched.py
index ccf8ce9..9a82a89 100644
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -71,10 +71,10 @@ class scheduler:
"""
if kwargs is _sentinel:
kwargs = {}
+ event = Event(time, priority, action, argument, kwargs)
with self._lock:
- event = Event(time, priority, action, argument, kwargs)
heapq.heappush(self._queue, event)
- return event # The ID
+ return event # The ID
def enter(self, delay, priority, action, argument=(), kwargs=_sentinel):
"""A variant that specifies the time as a relative time.
@@ -82,9 +82,8 @@ class scheduler:
This is actually the more commonly used interface.
"""
- with self._lock:
- time = self.timefunc() + delay
- return self.enterabs(time, priority, action, argument, kwargs)
+ time = self.timefunc() + delay
+ return self.enterabs(time, priority, action, argument, kwargs)
def cancel(self, event):
"""Remove an event from the queue.
@@ -165,4 +164,4 @@ class scheduler:
# the actual order they would be retrieved.
with self._lock:
events = self._queue[:]
- return map(heapq.heappop, [events]*len(events))
+ return map(heapq.heappop, [events]*len(events))