Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(391)

Side by Side Diff: Lib/threading.py

Issue 15139: Speed up threading.Condition wakeup
Patch Set: Created 10 months, 2 weeks ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/_threadmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Thread module emulating a subset of Java's threading model.""" 1 """Thread module emulating a subset of Java's threading model."""
2 2
3 import sys as _sys 3 import sys as _sys
4 import _thread 4 import _thread
5 5
6 from time import sleep as _sleep 6 from time import sleep as _sleep
7 try: 7 try:
8 from time import monotonic as _time 8 from time import monotonic as _time
9 except ImportError: 9 except ImportError:
10 from time import time as _time 10 from time import time as _time
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return True 173 return True
174 174
175 def wait(self, timeout=None): 175 def wait(self, timeout=None):
176 if not self._is_owned(): 176 if not self._is_owned():
177 raise RuntimeError("cannot wait on un-acquired lock") 177 raise RuntimeError("cannot wait on un-acquired lock")
178 waiter = _allocate_lock() 178 waiter = _allocate_lock()
179 waiter.acquire() 179 waiter.acquire()
180 self._waiters.append(waiter) 180 self._waiters.append(waiter)
181 saved_state = self._release_save() 181 saved_state = self._release_save()
182 try: # restore state no matter what (e.g., KeyboardInterrupt) 182 try: # restore state no matter what (e.g., KeyboardInterrupt)
183 if timeout is None: 183 gotit = waiter._acquire_condition(timeout, self._lock, saved_state)
184 waiter.acquire() 184 if not gotit:
185 gotit = True 185 try:
186 else: 186 self._waiters.remove(waiter)
187 if timeout > 0: 187 except ValueError:
188 gotit = waiter.acquire(True, timeout) 188 pass
189 else:
190 gotit = waiter.acquire(False)
191 if not gotit:
192 try:
193 self._waiters.remove(waiter)
194 except ValueError:
195 pass
196 return gotit 189 return gotit
197 finally: 190 finally:
198 self._acquire_restore(saved_state) 191 self._acquire_restore(saved_state)
199 192
200 def wait_for(self, predicate, timeout=None): 193 def wait_for(self, predicate, timeout=None):
201 endtime = None 194 endtime = None
202 waittime = timeout 195 waittime = timeout
203 result = predicate() 196 result = predicate()
204 while not result: 197 while not result:
205 if waittime is not None: 198 if waittime is not None:
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 thread._ident = ident 941 thread._ident = ident
949 new_active[ident] = thread 942 new_active[ident] = thread
950 else: 943 else:
951 # All the others are already stopped. 944 # All the others are already stopped.
952 thread._stop() 945 thread._stop()
953 946
954 _limbo.clear() 947 _limbo.clear()
955 _active.clear() 948 _active.clear()
956 _active.update(new_active) 949 _active.update(new_active)
957 assert len(_active) == 1 950 assert len(_active) == 1
OLDNEW
« no previous file with comments | « no previous file | Modules/_threadmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7