DebugClients/Python3/DebugClientThreads.py

branch
debugger speed
changeset 5174
8c48f5e0cd92
parent 5162
bbf2bb2d533c
equal deleted inserted replaced
5170:fb9168c2e069 5174:8c48f5e0cd92
8 """ 8 """
9 9
10 import _thread 10 import _thread
11 import sys 11 import sys
12 12
13 from AsyncIO import AsyncIO
14 from DebugThread import DebugThread 13 from DebugThread import DebugThread
15 import DebugClientBase 14 import DebugClientBase
16 15
17 16
18 def _debugclient_start_new_thread(target, args, kwargs={}): 17 def _debugclient_start_new_thread(target, args, kwargs={}):
47 # Note: import threading here AFTER above hook, as threading cache's 46 # Note: import threading here AFTER above hook, as threading cache's
48 # thread._start_new_thread. 47 # thread._start_new_thread.
49 from threading import RLock 48 from threading import RLock
50 49
51 50
52 class DebugClientThreads(DebugClientBase.DebugClientBase, AsyncIO): 51 class DebugClientThreads(DebugClientBase.DebugClientBase):
53 """ 52 """
54 Class implementing the client side of the debugger. 53 Class implementing the client side of the debugger.
55 54
56 This variant of the debugger implements a threaded debugger client 55 This variant of the debugger implements a threaded debugger client
57 by subclassing all relevant base classes. 56 by subclassing all relevant base classes.
58 """ 57 """
59 def __init__(self): 58 def __init__(self):
60 """ 59 """
61 Constructor 60 Constructor
62 """ 61 """
63 AsyncIO.__init__(self)
64
65 DebugClientBase.DebugClientBase.__init__(self) 62 DebugClientBase.DebugClientBase.__init__(self)
66 63
67 # protection lock for synchronization 64 # protection lock for synchronization
68 self.clientLock = RLock() 65 self.clientLock = RLock()
69 66
80 def attachThread(self, target=None, args=None, kwargs=None, 77 def attachThread(self, target=None, args=None, kwargs=None,
81 mainThread=False): 78 mainThread=False):
82 """ 79 """
83 Public method to setup a thread for DebugClient to debug. 80 Public method to setup a thread for DebugClient to debug.
84 81
85 If mainThread is non-zero, then we are attaching to the already 82 If mainThread is True, then we are attaching to the already
86 started mainthread of the app and the rest of the args are ignored. 83 started mainthread of the app and the rest of the args are ignored.
87 84
88 @param target the start function of the target thread (i.e. the 85 @param target the start function of the target thread (i.e. the
89 user code) 86 user code)
90 @param args arguments to pass to target 87 @param args arguments to pass to target
129 def lockClient(self, blocking=True): 126 def lockClient(self, blocking=True):
130 """ 127 """
131 Public method to acquire the lock for this client. 128 Public method to acquire the lock for this client.
132 129
133 @param blocking flag to indicating a blocking lock 130 @param blocking flag to indicating a blocking lock
131 @type bool
134 @return flag indicating successful locking 132 @return flag indicating successful locking
133 @rtype bool
135 """ 134 """
136 if blocking: 135 if blocking:
137 self.clientLock.acquire() 136 self.clientLock.acquire()
138 else: 137 else:
139 return self.clientLock.acquire(blocking) 138 return self.clientLock.acquire(blocking)
153 152
154 @param id the id the current thread should be set to. 153 @param id the id the current thread should be set to.
155 """ 154 """
156 try: 155 try:
157 self.lockClient() 156 self.lockClient()
158 if id is None: 157 if id is None or id not in self.threads:
159 self.currentThread = None 158 self.currentThread = None
160 else: 159 else:
161 self.currentThread = self.threads[id] 160 self.currentThread = self.threads[id]
162 finally: 161 finally:
163 self.unlockClient() 162 self.unlockClient()

eric ide

mercurial