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

Side by Side Diff: Lib/threading.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months 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 | « Lib/textwrap.py ('k') | Lib/tkinter/test/support.py » ('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 time as _time, sleep as _sleep 6 from time import time as _time, sleep as _sleep
7 from traceback import format_exc as _format_exc 7 from traceback import format_exc as _format_exc
8 from collections import deque 8 from collections import deque
9 from _weakrefset import WeakSet
10 9
11 # Note regarding PEP 8 compliant names 10 # Note regarding PEP 8 compliant names
12 # This threading model was originally inspired by Java, and inherited 11 # This threading model was originally inspired by Java, and inherited
13 # the convention of camelCase function and method names from that 12 # the convention of camelCase function and method names from that
14 # language. Those originaly names are not in any imminent danger of 13 # language. Those originaly names are not in any imminent danger of
15 # being deprecated (even for Py3k),so this module provides them as an 14 # being deprecated (even for Py3k),so this module provides them as an
16 # alias for the PEP 8 compliant names 15 # alias for the PEP 8 compliant names
17 # Note that using the new PEP 8 compliant names facilitates substitution 16 # Note that using the new PEP 8 compliant names facilitates substitution
18 # with the multiprocessing module, which doesn't provide the old 17 # with the multiprocessing module, which doesn't provide the old
19 # Java inspired names. 18 # Java inspired names.
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 def _newname(template="Thread-%d"): 601 def _newname(template="Thread-%d"):
603 global _counter 602 global _counter
604 _counter = _counter + 1 603 _counter = _counter + 1
605 return template % _counter 604 return template % _counter
606 605
607 # Active thread administration 606 # Active thread administration
608 _active_limbo_lock = _allocate_lock() 607 _active_limbo_lock = _allocate_lock()
609 _active = {} # maps thread id to Thread object 608 _active = {} # maps thread id to Thread object
610 _limbo = {} 609 _limbo = {}
611 610
612 # For debug and leak testing
613 _dangling = WeakSet()
614 611
615 # Main class for threads 612 # Main class for threads
616 613
617 class Thread(_Verbose): 614 class Thread(_Verbose):
618 615
619 __initialized = False 616 __initialized = False
620 # Need to store a reference to sys.exc_info for printing 617 # Need to store a reference to sys.exc_info for printing
621 # out exceptions when a thread tries to use a global var. during interp. 618 # out exceptions when a thread tries to use a global var. during interp.
622 # shutdown and thus raises an exception about trying to perform some 619 # shutdown and thus raises an exception about trying to perform some
623 # operation on/with a NoneType 620 # operation on/with a NoneType
(...skipping 17 matching lines...) Expand all
641 else: 638 else:
642 self._daemonic = current_thread().daemon 639 self._daemonic = current_thread().daemon
643 self._ident = None 640 self._ident = None
644 self._started = Event() 641 self._started = Event()
645 self._stopped = False 642 self._stopped = False
646 self._block = Condition(Lock()) 643 self._block = Condition(Lock())
647 self._initialized = True 644 self._initialized = True
648 # sys.stderr is not stored in the class like 645 # sys.stderr is not stored in the class like
649 # sys.exc_info since it can be changed between instances 646 # sys.exc_info since it can be changed between instances
650 self._stderr = _sys.stderr 647 self._stderr = _sys.stderr
651 _dangling.add(self)
652 648
653 def _reset_internal_locks(self): 649 def _reset_internal_locks(self):
654 # private! Called by _after_fork() to reset our internal locks as 650 # private! Called by _after_fork() to reset our internal locks as
655 # they may be in an invalid state leading to a deadlock or crash. 651 # they may be in an invalid state leading to a deadlock or crash.
656 if hasattr(self, '_block'): # DummyThread deletes _block 652 if hasattr(self, '_block'): # DummyThread deletes _block
657 self._block.__init__() 653 self._block.__init__()
658 self._started._reset_internal_locks() 654 self._started._reset_internal_locks()
659 655
660 def __repr__(self): 656 def __repr__(self):
661 assert self._initialized, "Thread.__init__() was not called" 657 assert self._initialized, "Thread.__init__() was not called"
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 # All the others are already stopped. 1071 # All the others are already stopped.
1076 # We don't call _Thread__stop() because it tries to acquire 1072 # We don't call _Thread__stop() because it tries to acquire
1077 # thread._Thread__block which could also have been held while 1073 # thread._Thread__block which could also have been held while
1078 # we forked. 1074 # we forked.
1079 thread._stopped = True 1075 thread._stopped = True
1080 1076
1081 _limbo.clear() 1077 _limbo.clear()
1082 _active.clear() 1078 _active.clear()
1083 _active.update(new_active) 1079 _active.update(new_active)
1084 assert len(_active) == 1 1080 assert len(_active) == 1
OLDNEW
« no previous file with comments | « Lib/textwrap.py ('k') | Lib/tkinter/test/support.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+