Thu, 06 Oct 2016 22:51:04 +0200
Make attachThread and dumpThreadList runnable again.
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
2 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
3 | # Copyright (c) 2014 - 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
4 | # |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
5 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
6 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
7 | Module implementing an import hook patching thread modules to get debugged too. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
8 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
9 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
10 | import os.path |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
11 | import sys |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
12 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
13 | if sys.version_info[0] == 2: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
14 | import thread as _thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
15 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | import _thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
17 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
18 | import threading |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
19 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
20 | from DebugBase import DebugBase |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
21 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
22 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
23 | class ThreadExtension(object): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
24 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
25 | Class implementing the thread support for the debugger. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
26 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
27 | Provides methods for intercepting thread creation, retriving the running |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
28 | threads and their name and state. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
29 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
30 | def __init__(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
31 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
32 | Constructor |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
33 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
34 | self.threadNumber = 1 |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
35 | self._original_start_new_thread = None |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
36 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
37 | self.clientLock = threading.RLock() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
38 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
39 | # dictionary of all threads running {id: DebugBase} |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
40 | self.threads = {_thread.get_ident(): self} |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
41 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
42 | # the "current" thread, basically for variables view |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
43 | self.currentThread = self |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
44 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
45 | # special objects representing the main scripts thread and frame |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
46 | self.mainThread = self |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
47 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
48 | if sys.version_info[0] == 2: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
49 | self.threadModName = 'thread' |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
50 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
51 | self.threadModName = '_thread' |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
52 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
53 | # reset already imported thread module to apply hooks at next import |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
54 | del sys.modules[self.threadModName] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
55 | del sys.modules['threading'] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
56 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
57 | # provide a hook to perform a hard breakpoint |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
58 | # Use it like this: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
59 | # if hasattr(sys, 'breakpoint): sys.breakpoint() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
60 | sys.breakpoint = self.set_trace |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
62 | def attachThread(self, target=None, args=None, kwargs={}, |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
63 | mainThread=False): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
64 | """ |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
65 | Public method to setup a standard thread for DebugClient to debug. |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
67 | If mainThread is True, then we are attaching to the already |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
68 | started mainthread of the app and the rest of the args are ignored. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
69 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
70 | @param target the start function of the target thread (i.e. the user |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
71 | code) |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
72 | @param args arguments to pass to target |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
73 | @param kwargs keyword arguments to pass to target |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | @param mainThread True, if we are attaching to the already |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
75 | started mainthread of the app |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | @return identifier of the created thread |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
77 | """ |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
78 | if mainThread: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
79 | ident = _thread.get_ident() |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
80 | name = 'MainThread' |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
81 | newThread = self.mainThread |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
82 | newThread._mainThread = True |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
83 | if self.debugging: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
84 | sys.setprofile(newThread.profile) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
85 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
86 | else: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
87 | newThread = DebugBase(self) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
88 | ident = self._original_start_new_thread( |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
89 | newThread.bootstrap, (target, args, kwargs)) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
90 | name = 'Thread-{0}'.format(self.threadNumber) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
91 | self.threadNumber += 1 |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
92 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
93 | newThread.id = ident |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
94 | newThread.name = name |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
95 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
96 | self.threads[ident] = newThread |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
97 | |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
98 | return ident |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
99 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
100 | def threadTerminated(self, dbgThread): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
101 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
102 | Public method called when a DebugThread has exited. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
103 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
104 | @param dbgThread the DebugThread that has exited |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
105 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
106 | self.lockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
107 | try: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
108 | del self.threads[dbgThread.get_ident()] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
109 | except KeyError: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
110 | pass |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
111 | finally: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
112 | self.unlockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
113 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
114 | def lockClient(self, blocking=True): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
115 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
116 | Public method to acquire the lock for this client. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
117 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
118 | @param blocking flag to indicating a blocking lock |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
119 | @type bool |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
120 | @return flag indicating successful locking |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
121 | @rtype bool |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
122 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
123 | if blocking: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
124 | self.clientLock.acquire() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
125 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
126 | return self.clientLock.acquire(blocking) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
127 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
128 | def unlockClient(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
129 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
130 | Public method to release the lock for this client. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
131 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
132 | try: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
133 | self.clientLock.release() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
134 | except AssertionError: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
135 | pass |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
136 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
137 | def setCurrentThread(self, id): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
138 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
139 | Public method to set the current thread. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
140 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
141 | @param id the id the current thread should be set to. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
142 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
143 | try: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
144 | self.lockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
145 | if id is None or id not in self.threads: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
146 | self.currentThread = None |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
147 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
148 | self.currentThread = self.threads[id] |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
149 | finally: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
150 | self.unlockClient() |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
151 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
152 | def dumpThreadList(self): |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
153 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
154 | Public method to send the list of threads. |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
155 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
156 | threadList = [] |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
157 | if len(self.threads) > 1: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
158 | currentId = _thread.get_ident() |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
159 | # update thread names set by user (threading.setName) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
160 | threadNames = {t.ident: t.getName() for t in threading.enumerate()} |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
161 | |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
162 | for id, thd in self.threads.items(): |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
163 | d = {"id": id} |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
164 | try: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
165 | d["name"] = threadNames.get(id, thd.name) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
166 | d["broken"] = thd.isBroken |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
167 | except Exception: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
168 | d["name"] = 'UnknownThread' |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
169 | d["broken"] = False |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
170 | |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
171 | threadList.append(d) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
172 | else: |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
173 | currentId = -1 |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
174 | d = {"id": -1} |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
175 | d["name"] = "MainThread" |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
176 | d["broken"] = self.isBroken |
5207
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
177 | threadList.append(d) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
178 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
179 | self.sendJsonCommand("ResponseThreadList", { |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
180 | "currentID": currentId, |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
181 | "threadList": threadList, |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
182 | }) |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
183 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
184 | |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
185 | # |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
186 | # eflag: noqa = M702 |