Tue, 07 Nov 2023 16:52:08 +0100
Changed the use of the deprecated Thread.getName() to a direct access of the Thread.name property.
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 | |
9653
e67609152c5e
Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
3 | # Copyright (c) 2014 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
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
|
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 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
10 | import _thread |
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
11 | import contextlib |
7376
21df384d6150
Added some inspirations received from Tobias.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7364
diff
changeset
|
12 | import os |
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
|
13 | 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
|
14 | 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
|
15 | |
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 | 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
|
17 | |
5552
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
18 | _qtThreadNumber = 1 |
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
19 | |
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
|
20 | |
8207
d359172d11be
Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7986
diff
changeset
|
21 | class ThreadExtension: |
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
|
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 implementing the thread support for the debugger. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
7390
052ce4cf06c6
Added a todo comment.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7376
diff
changeset
|
25 | Provides methods for intercepting thread creation, retrieving the running |
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
|
26 | 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
|
27 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
28 | |
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
|
29 | 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
|
30 | """ |
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 | 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
|
32 | """ |
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 | 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
|
34 | self._original_start_new_thread = None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
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
|
36 | self.clientLock = threading.RLock() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | |
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
|
38 | # 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
|
39 | 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
|
40 | |
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 | # 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
|
42 | self.currentThread = self |
5221
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset
|
43 | # the thread we are at a breakpoint continuing at next command |
960afd19c1b6
Give the next debugger command to the thread where we are stopped at the moment.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5209
diff
changeset
|
44 | self.currentThreadExec = self |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
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
|
46 | # 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
|
47 | 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
|
48 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | def attachThread(self, target=None, args=None, kwargs=None, mainThread=False): |
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
|
50 | """ |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
51 | Public method to setup a standard thread for DebugClient to debug. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
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
|
53 | 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
|
54 | started mainthread of the app and the rest of the args are ignored. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
56 | @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
|
57 | 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
|
58 | @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
|
59 | @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
|
60 | @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
|
61 | 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
|
62 | @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
|
63 | """ |
5651
982465f8389c
Fixed a few code style issues related to the usage of mutable types for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5647
diff
changeset
|
64 | if kwargs is None: |
982465f8389c
Fixed a few code style issues related to the usage of mutable types for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5647
diff
changeset
|
65 | kwargs = {} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
67 | if mainThread: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
68 | ident = _thread.get_ident() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | name = "MainThread" |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
70 | newThread = self.mainThread |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
71 | newThread.isMainThread = True |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
72 | if self.debugging: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
73 | sys.setprofile(newThread.profile) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
74 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
75 | else: |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
76 | newThread = DebugBase(self) |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
77 | ident = self._original_start_new_thread( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | newThread.bootstrap, (target, args, kwargs) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | name = "Thread-{0}".format(self.threadNumber) |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
81 | self.threadNumber += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
83 | newThread.id = ident |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
84 | newThread.name = name |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
85 | |
5208
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
86 | self.threads[ident] = newThread |
aa8045780ce4
Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5207
diff
changeset
|
87 | |
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
|
88 | return ident |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
90 | def threadTerminated(self, threadId): |
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
|
91 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
92 | Public method called when a DebugThread has exited. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
94 | @param threadId id of the DebugThread that has exited |
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
95 | @type int |
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
|
96 | """ |
7283629b02c0
Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
97 | 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
|
98 | try: |
8240
93b8a353c4bf
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 1).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
99 | with contextlib.suppress(KeyError): |
93b8a353c4bf
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 1).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
100 | del self.threads[threadId] |
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
|
101 | 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
|
102 | self.unlockClient() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | |
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
|
104 | 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
|
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 | Public method to acquire the lock for this client. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
107 | |
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
|
108 | @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
|
109 | @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
|
110 | @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
|
111 | @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
|
112 | """ |
7986
2971d5d19951
Fixed a few thread related issues in the debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
113 | return self.clientLock.acquire(blocking) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | |
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
|
115 | 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
|
116 | """ |
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 | 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
|
118 | """ |
8240
93b8a353c4bf
Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 1).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8218
diff
changeset
|
119 | with contextlib.suppress(RuntimeError): |
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
|
120 | self.clientLock.release() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
122 | def setCurrentThread(self, threadId): |
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
|
123 | """ |
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 | 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
|
125 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
126 | @param threadId the id the current thread should be set to. |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
127 | @type int |
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
|
128 | """ |
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 | 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
|
130 | self.lockClient() |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
131 | if threadId is None: |
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
|
132 | 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
|
133 | else: |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
134 | self.currentThread = self.threads.get(threadId) |
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
|
135 | 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
|
136 | self.unlockClient() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
137 | |
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
|
138 | 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
|
139 | """ |
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 | 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
|
141 | """ |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
142 | self.updateThreadList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
143 | |
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
|
144 | threadList = [] |
7417
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
145 | currentId = _thread.get_ident() |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
146 | # update thread names set by user (threading.setName) |
10293
6c5585c3e543
Changed the use of the deprecated Thread.getName() to a direct access of the Thread.name property.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
147 | threadNames = {t.ident: t.name for t in threading.enumerate()} |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
148 | |
7417
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
149 | for threadId, thd in self.threads.items(): |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
150 | d = {"id": threadId} |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
151 | try: |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
152 | d["name"] = threadNames.get(threadId, thd.name) |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
153 | d["broken"] = thd.isBroken |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
154 | d["except"] = thd.isException |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
155 | except Exception: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
156 | d["name"] = "UnknownThread" |
7417
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
157 | d["broken"] = False |
9391a330f50f
Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7416
diff
changeset
|
158 | d["except"] = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
159 | |
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
|
160 | threadList.append(d) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
161 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | self.sendJsonCommand( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
163 | "ResponseThreadList", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
164 | { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
165 | "currentID": currentId, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
166 | "threadList": threadList, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
167 | }, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
168 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
169 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
170 | def getExecutedFrame(self, frame): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
171 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
172 | Public method to return the currently executed frame. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
173 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
174 | @param frame the current frame |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
175 | @type frame object |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
176 | @return the frame which is excecuted (without debugger frames) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
177 | @rtype frame object |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
178 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
179 | # to get the currently executed frame, skip all frames belonging to the |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
180 | # debugger |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
181 | while frame is not None: |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
182 | baseName = os.path.basename(frame.f_code.co_filename) |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
183 | if not baseName.startswith( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
184 | ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
185 | "DebugClientBase.py", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
186 | "DebugBase.py", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
187 | "AsyncFile.py", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
188 | "ThreadExtension.py", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
190 | ): |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
191 | break |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
192 | frame = frame.f_back |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
193 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
194 | return frame |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
195 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
196 | def updateThreadList(self): |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
197 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
198 | Public method to update the list of running threads. |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
199 | """ |
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
200 | frames = sys._current_frames() |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
201 | for threadId, frame in frames.items(): |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
202 | # skip our own timer thread |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
203 | if frame.f_code.co_name == "__eventPollTimer": |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
204 | continue |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
205 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
206 | # Unknown thread |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
207 | if threadId not in self.threads: |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
208 | newThread = DebugBase(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
209 | name = "Thread-{0}".format(self.threadNumber) |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
210 | self.threadNumber += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
211 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
212 | newThread.id = threadId |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
213 | newThread.name = name |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
214 | self.threads[threadId] = newThread |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
215 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
216 | # adjust current frame |
5269
0e96e1557c45
Fix for PyPy showing no local variables and suppress exception on old frames.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5240
diff
changeset
|
217 | if "__pypy__" not in sys.builtin_module_names: |
5561
5fffb5cc1a88
When in unhandled exception, current frame lies in debugger files always. In breakpoints,
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5552
diff
changeset
|
218 | # Don't update with None |
5fffb5cc1a88
When in unhandled exception, current frame lies in debugger files always. In breakpoints,
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5552
diff
changeset
|
219 | currentFrame = self.getExecutedFrame(frame) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
220 | if ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
221 | currentFrame is not None |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
222 | and self.threads[threadId].isBroken is False |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
223 | ): |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5581
diff
changeset
|
224 | self.threads[threadId].currentFrame = currentFrame |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
225 | |
5222
6548dc1bfd48
Collect all running threads, even if they were not started by the debug client.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5221
diff
changeset
|
226 | # Clean up obsolet because terminated threads |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
227 | self.threads = { |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
228 | id_: thrd for id_, thrd in self.threads.items() if id_ in frames |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
229 | } |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
230 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
231 | ####################################################################### |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
232 | ## Methods below deal with patching various modules to support |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
233 | ## debugging of threads. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
234 | ####################################################################### |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
235 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
236 | def patchPyThread(self, module): |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
237 | """ |
8334
c113428ecff3
Removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
238 | Public method to patch Python _thread module. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
239 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
240 | @param module reference to the imported module to be patched |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
241 | @type module |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
242 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
243 | # make thread hooks available to system |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
244 | self._original_start_new_thread = module.start_new_thread |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
245 | module.start_new_thread = self.attachThread |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
246 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
247 | def patchGreenlet(self, module): |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
248 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
249 | Public method to patch the 'greenlet' module. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
250 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
251 | @param module reference to the imported module to be patched |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
252 | @type module |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
253 | @return flag indicating that the module was processed |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
254 | @rtype bool |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
255 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
256 | # Check for greenlet.settrace |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
257 | if hasattr(module, "settrace"): |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
258 | DebugBase.pollTimerEnabled = False |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
259 | return True |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
260 | return False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
261 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
262 | def patchPyThreading(self, module): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
263 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
264 | Public method to patch the Python threading module. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
265 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
266 | @param module reference to the imported module to be patched |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
267 | @type module |
5209
cd058aa6af37
Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5208
diff
changeset
|
268 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
269 | # _debugClient as a class attribute can't be accessed in following |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
270 | # class. Therefore we need a global variable. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
271 | _debugClient = self |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
272 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
273 | def _bootstrap(self, run): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
274 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
275 | Bootstrap for threading, which reports exceptions correctly. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
276 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
277 | @param run the run method of threading.Thread |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
278 | @type method pointer |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
279 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
280 | newThread = DebugBase(_debugClient) |
7416
6f899e82f9a2
Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7415
diff
changeset
|
281 | newThread.name = self.name |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
282 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
283 | _debugClient.threads[self.ident] = newThread |
7416
6f899e82f9a2
Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7415
diff
changeset
|
284 | _debugClient.dumpThreadList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
285 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
286 | # see DebugBase.bootstrap |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
287 | sys.settrace(newThread.trace_dispatch) |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
288 | try: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
289 | run() |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
290 | except Exception: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
291 | excinfo = sys.exc_info() |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
292 | newThread.user_exception(excinfo, True) |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
293 | finally: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
294 | sys.settrace(None) |
7416
6f899e82f9a2
Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7415
diff
changeset
|
295 | _debugClient.dumpThreadList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
296 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
297 | class ThreadWrapper(module.Thread): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
298 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
299 | Wrapper class for threading.Thread. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
300 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
301 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
302 | def __init__(self, *args, **kwargs): |
5552
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
303 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
304 | Constructor |
6196
7135a692e43e
Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6195
diff
changeset
|
305 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
306 | # Overwrite the provided run method with our own, to |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
307 | # intercept the thread creation by threading.Thread |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
308 | self.run = lambda s=self, run=self.run: _bootstrap(s, run) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
309 | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
310 | super().__init__(*args, **kwargs) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
311 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
312 | module.Thread = ThreadWrapper |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
313 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
314 | # Special handling of threading.(_)Timer |
7646
39e3db2b4936
Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
diff
changeset
|
315 | timer = module.Timer |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
316 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
317 | class TimerWrapper(timer, ThreadWrapper): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
318 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
319 | Wrapper class for threading.(_)Timer. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
320 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
321 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
322 | def __init__(self, interval, function, *args, **kwargs): |
6196
7135a692e43e
Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6195
diff
changeset
|
323 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
324 | Constructor |
6196
7135a692e43e
Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6195
diff
changeset
|
325 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
326 | super().__init__(interval, function, *args, **kwargs) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | |
7646
39e3db2b4936
Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
diff
changeset
|
328 | module.Timer = TimerWrapper |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
330 | # Special handling of threading._DummyThread |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
331 | class DummyThreadWrapper(module._DummyThread, ThreadWrapper): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
332 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
333 | Wrapper class for threading._DummyThread. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
334 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
335 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
336 | def __init__(self, *args, **kwargs): |
7364
bcf6b40e7790
Fixed thread creation on uninitialized threads (found in git-cola project).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
7360
diff
changeset
|
337 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
338 | Constructor |
7364
bcf6b40e7790
Fixed thread creation on uninitialized threads (found in git-cola project).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
7360
diff
changeset
|
339 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
340 | super().__init__(*args, **kwargs) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
341 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
342 | module._DummyThread = DummyThreadWrapper |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
343 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
344 | def patchQThread(self, module): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
345 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
346 | Public method to patch the QtCore module's QThread. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
347 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
348 | @param module reference to the imported module to be patched |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
349 | @type module |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
350 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
351 | # _debugClient as a class attribute can't be accessed in following |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
352 | # class. Therefore we need a global variable. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
353 | _debugClient = self |
5552
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
354 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
355 | def _bootstrapQThread(self, run): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
356 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
357 | Bootstrap for QThread, which reports exceptions correctly. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
358 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
359 | @param run the run method of *.QThread |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
360 | @type method pointer |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
361 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
362 | global _qtThreadNumber |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
363 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
364 | newThread = DebugBase(_debugClient) |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
365 | ident = _thread.get_ident() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
366 | name = "QtThread-{0}".format(_qtThreadNumber) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
367 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
368 | _qtThreadNumber += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
370 | newThread.id = ident |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
371 | newThread.name = name |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
372 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
373 | _debugClient.threads[ident] = newThread |
7416
6f899e82f9a2
Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7415
diff
changeset
|
374 | _debugClient.dumpThreadList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
375 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
376 | # see DebugBase.bootstrap |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
377 | sys.settrace(newThread.trace_dispatch) |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
378 | try: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
379 | run() |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
380 | except SystemExit: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
381 | # *.QThreads doesn't like SystemExit |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
382 | pass |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
383 | except Exception: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
384 | excinfo = sys.exc_info() |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
385 | newThread.user_exception(excinfo, True) |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
386 | finally: |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
387 | sys.settrace(None) |
7416
6f899e82f9a2
Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7415
diff
changeset
|
388 | _debugClient.dumpThreadList() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
389 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
390 | class QThreadWrapper(module.QThread): |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
391 | """ |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
392 | Wrapper class for *.QThread. |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
393 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
394 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
395 | def __init__(self, *args, **kwargs): |
5552
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
396 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
397 | Constructor |
5552
313a91a38aed
Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
5544
diff
changeset
|
398 | """ |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
399 | # Overwrite the provided run method with our own, to |
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
400 | # intercept the thread creation by Qt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
401 | self.run = lambda s=self, run=self.run: (_bootstrapQThread(s, run)) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
402 | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
403 | super().__init__(*args, **kwargs) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
404 | |
7415 | 405 | class QRunnableWrapper(module.QRunnable): |
406 | """ | |
407 | Wrapper class for *.QRunnable. | |
408 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
409 | |
7415 | 410 | def __init__(self, *args, **kwargs): |
6196
7135a692e43e
Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6195
diff
changeset
|
411 | """ |
7415 | 412 | Constructor |
6196
7135a692e43e
Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6195
diff
changeset
|
413 | """ |
7415 | 414 | # Overwrite the provided run method with our own, to |
415 | # intercept the thread creation by Qt | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
416 | self.run = lambda s=self, run=self.run: (_bootstrapQThread(s, run)) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
417 | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
418 | super().__init__(*args, **kwargs) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
419 | |
7404
663f1c3d6f53
Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7390
diff
changeset
|
420 | module.QThread = QThreadWrapper |
7415 | 421 | module.QRunnable = QRunnableWrapper |