]> granicus.if.org Git - python/commitdiff
Issue #16640: Run less code under a lock in sched module.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 29 Dec 2012 19:46:37 +0000 (21:46 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 29 Dec 2012 19:46:37 +0000 (21:46 +0200)
Lib/sched.py
Misc/NEWS

index ccf8ce907428e1be6939c2de2f769b4f28303d3b..9a82a89688d0ea77ff3f05811bd404317cc2e4a7 100644 (file)
@@ -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))
index 08c0d90fbb4c9e837585fa6ce5f6512ae94314a7..f606654a15e0ea0aa2544793d9b1773db665a359 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #16640: Run less code under a lock in sched module.
+
 - Issue #16165: Fix sched.scheduler.run() method was block a scheduler for
   other threads.