[Python-checkins] cpython: Issue #16640: Run less code under a lock in sched module.

serhiy.storchaka python-checkins at python.org
Sat Dec 29 20:48:56 CET 2012


http://hg.python.org/cpython/rev/1bed43c0a5af
changeset:   81138:1bed43c0a5af
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Dec 29 21:46:37 2012 +0200
summary:
  Issue #16640: Run less code under a lock in sched module.

files:
  Lib/sched.py |  11 +++++------
  Misc/NEWS    |   2 ++
  2 files changed, 7 insertions(+), 6 deletions(-)


diff --git a/Lib/sched.py b/Lib/sched.py
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -71,10 +71,10 @@
         """
         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 @@
         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 @@
         # 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))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,8 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list