DebugClients/Python3/DebugThread.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
10 import bdb 10 import bdb
11 import sys 11 import sys
12 12
13 from DebugBase import * 13 from DebugBase import *
14 14
15
15 class DebugThread(DebugBase): 16 class DebugThread(DebugBase):
16 """ 17 """
17 Class implementing a debug thread. 18 Class implementing a debug thread.
18 19
19 It represents a thread in the python interpreter that we are tracing. 20 It represents a thread in the python interpreter that we are tracing.
20 21
21 Provides simple wrapper methods around bdb for the 'owning' client to 22 Provides simple wrapper methods around bdb for the 'owning' client to
22 call to step etc. 23 call to step etc.
23 """ 24 """
24 def __init__(self, dbgClient, targ = None, args = None, kwargs = None, 25 def __init__(self, dbgClient, targ=None, args=None, kwargs=None,
25 mainThread = False): 26 mainThread=False):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param dbgClient the owning client 30 @param dbgClient the owning client
30 @param targ the target method in the run thread 31 @param targ the target method in the run thread
32 @param kwargs arguments to be passed to the thread 33 @param kwargs arguments to be passed to the thread
33 @param mainThread 0 if this thread is not the mainscripts thread 34 @param mainThread 0 if this thread is not the mainscripts thread
34 """ 35 """
35 DebugBase.__init__(self, dbgClient) 36 DebugBase.__init__(self, dbgClient)
36 37
37 self._target = targ 38 self._target = targ
38 self._args = args 39 self._args = args
39 self._kwargs = kwargs 40 self._kwargs = kwargs
40 self._mainThread = mainThread 41 self._mainThread = mainThread
41 # thread running tracks execution state of client code 42 # thread running tracks execution state of client code
42 # it will always be False for main thread as that is tracked 43 # it will always be False for main thread as that is tracked
43 # by DebugClientThreads and Bdb... 44 # by DebugClientThreads and Bdb...
44 self._threadRunning = False 45 self._threadRunning = False
45 46
46 self.__ident = None # id of this thread. 47 self.__ident = None # id of this thread.
47 self.__name = "" 48 self.__name = ""
48 49
49 def set_ident(self, id): 50 def set_ident(self, id):
50 """ 51 """
51 Public method to set the id for this thread. 52 Public method to set the id for this thread.
80 81
81 def bootstrap(self): 82 def bootstrap(self):
82 """ 83 """
83 Private method to bootstrap the thread. 84 Private method to bootstrap the thread.
84 85
85 It wraps the call to the user function to enable tracing 86 It wraps the call to the user function to enable tracing
86 before hand. 87 before hand.
87 """ 88 """
88 try: 89 try:
89 self._threadRunning = True 90 self._threadRunning = True
90 self.traceThread() 91 self.traceThread()
111 @param arg The arguments 112 @param arg The arguments
112 @return local trace function 113 @return local trace function
113 """ 114 """
114 try: 115 try:
115 self._dbgClient.lockClient() 116 self._dbgClient.lockClient()
116 # if this thread came out of a lock, and we are quitting 117 # if this thread came out of a lock, and we are quitting
117 # and we are still running, then get rid of tracing for this thread 118 # and we are still running, then get rid of tracing for this thread
118 if self.quitting and self._threadRunning: 119 if self.quitting and self._threadRunning:
119 sys.settrace(None) 120 sys.settrace(None)
120 sys.setprofile(None) 121 sys.setprofile(None)
121 import threading 122 import threading
122 self.__name = threading.current_thread().name 123 self.__name = threading.current_thread().name

eric ide

mercurial