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

Delta Between Two Patch Sets: Lib/threading.py

Issue 19817: tracemalloc add a memory limit feature
Left Patch Set: Created 6 years, 4 months ago
Right Patch Set: Created 6 years, 3 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:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/unittest/case.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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
11 from traceback import format_exc as _format_exc 11 from traceback import format_exc as _format_exc
12 from _weakrefset import WeakSet 12 from _weakrefset import WeakSet
13 from itertools import islice as _islice 13 from itertools import islice as _islice
14 try: 14 try:
15 from _collections import deque as _deque 15 from _collections import deque as _deque
16 except ImportError: 16 except ImportError:
17 from collections import deque as _deque 17 from collections import deque as _deque
18
19 import tracemalloc
18 20
19 # Note regarding PEP 8 compliant names 21 # Note regarding PEP 8 compliant names
20 # This threading model was originally inspired by Java, and inherited 22 # This threading model was originally inspired by Java, and inherited
21 # the convention of camelCase function and method names from that 23 # the convention of camelCase function and method names from that
22 # language. Those original names are not in any imminent danger of 24 # language. Those original names are not in any imminent danger of
23 # being deprecated (even for Py3k),so this module provides them as an 25 # being deprecated (even for Py3k),so this module provides them as an
24 # alias for the PEP 8 compliant names 26 # alias for the PEP 8 compliant names
25 # Note that using the new PEP 8 compliant names facilitates substitution 27 # Note that using the new PEP 8 compliant names facilitates substitution
26 # with the multiprocessing module, which doesn't provide the old 28 # with the multiprocessing module, which doesn't provide the old
27 # Java inspired names. 29 # Java inspired names.
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 843
842 """ 844 """
843 if not self._initialized: 845 if not self._initialized:
844 raise RuntimeError("thread.__init__() not called") 846 raise RuntimeError("thread.__init__() not called")
845 847
846 if self._started.is_set(): 848 if self._started.is_set():
847 raise RuntimeError("threads can only be started once") 849 raise RuntimeError("threads can only be started once")
848 with _active_limbo_lock: 850 with _active_limbo_lock:
849 _limbo[self] = self 851 _limbo[self] = self
850 try: 852 try:
853 tracemalloc.stop()
851 _start_new_thread(self._bootstrap, ()) 854 _start_new_thread(self._bootstrap, ())
852 except Exception: 855 except Exception:
853 with _active_limbo_lock: 856 with _active_limbo_lock:
854 del _limbo[self] 857 del _limbo[self]
855 raise 858 raise
856 self._started.wait() 859 self._started.wait()
857 860
858 def run(self): 861 def run(self):
859 """Method representing the thread's activity. 862 """Method representing the thread's activity.
860 863
(...skipping 17 matching lines...) Expand all
878 # happen when a daemon thread wakes up at an unfortunate 881 # happen when a daemon thread wakes up at an unfortunate
879 # moment, finds the world around it destroyed, and raises some 882 # moment, finds the world around it destroyed, and raises some
880 # random exception *** while trying to report the exception in 883 # random exception *** while trying to report the exception in
881 # _bootstrap_inner() below ***. Those random exceptions 884 # _bootstrap_inner() below ***. Those random exceptions
882 # don't help anybody, and they confuse users, so we suppress 885 # don't help anybody, and they confuse users, so we suppress
883 # them. We suppress them only when it appears that the world 886 # them. We suppress them only when it appears that the world
884 # indeed has already been destroyed, so that exceptions in 887 # indeed has already been destroyed, so that exceptions in
885 # _bootstrap_inner() during normal business hours are properly 888 # _bootstrap_inner() during normal business hours are properly
886 # reported. Also, we only suppress them for daemonic threads; 889 # reported. Also, we only suppress them for daemonic threads;
887 # if a non-daemonic encounters this, something else is wrong. 890 # if a non-daemonic encounters this, something else is wrong.
891 tracemalloc.stop()
888 try: 892 try:
889 self._bootstrap_inner() 893 self._bootstrap_inner()
890 except: 894 except:
891 if self._daemonic and _sys is None: 895 if self._daemonic and _sys is None:
892 return 896 return
893 raise 897 raise
894 898
895 def _set_ident(self): 899 def _set_ident(self):
896 self._ident = get_ident() 900 self._ident = get_ident()
897 901
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 new_active[ident] = thread 1354 new_active[ident] = thread
1351 else: 1355 else:
1352 # All the others are already stopped. 1356 # All the others are already stopped.
1353 thread._reset_internal_locks(False) 1357 thread._reset_internal_locks(False)
1354 thread._stop() 1358 thread._stop()
1355 1359
1356 _limbo.clear() 1360 _limbo.clear()
1357 _active.clear() 1361 _active.clear()
1358 _active.update(new_active) 1362 _active.update(new_active)
1359 assert len(_active) == 1 1363 assert len(_active) == 1
LEFTRIGHT

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