eric6/DebugClients/Python/ThreadExtension.py

Mon, 21 Dec 2020 10:45:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 21 Dec 2020 10:45:10 +0100
changeset 7904
0424ebe2d3b1
parent 7646
39e3db2b4936
child 7923
91e843545d9a
permissions
-rw-r--r--

DebugBase: fixed an issue with Python < 3.7.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
3 # Copyright (c) 2014 - 2020 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
7376
21df384d6150 Added some inspirations received from Tobias.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7364
diff changeset
10 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
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
7637
c878e8255972 Removed some more Python2 related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7635
diff changeset
13 import _thread
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
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
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 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
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.
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
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 """
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 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
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 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
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 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
33 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
34
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.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
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 # 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
38 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
39
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 # 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
41 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
42 # 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
43 self.currentThreadExec = 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
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
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
48 def attachThread(self, target=None, args=None, kwargs=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
49 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
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.
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
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 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.
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
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 = {}
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
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()
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
69 name = 'MainThread'
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)
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
74
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(
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
78 newThread.bootstrap, (target, args, kwargs))
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
79 name = 'Thread-{0}'.format(self.threadNumber)
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
80 self.threadNumber += 1
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
81
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
82 newThread.id = ident
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
83 newThread.name = name
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
84
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
85 self.threads[ident] = newThread
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
86
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
87 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
88
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
89 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
90 """
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 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
92
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
93 @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
94 @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
95 """
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 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
97 try:
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
98 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
99 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
100 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
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()
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 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.
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
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 """
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 if blocking:
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
114 return self.clientLock.acquire()
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 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
116 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
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 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
119 """
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 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
121 """
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 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
123 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
124 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
125 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
126
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5581
diff changeset
127 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
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 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
130
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 @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
132 @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
133 """
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 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
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 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
144 """
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 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
146 """
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
147 self.updateThreadList()
7417
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
148
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
149 threadList = []
7417
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
150 currentId = _thread.get_ident()
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
151 # update thread names set by user (threading.setName)
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
152 threadNames = {t.ident: t.getName() for t in threading.enumerate()}
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
153
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
154 for threadId, thd in self.threads.items():
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
155 d = {"id": threadId}
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
156 try:
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
157 d["name"] = threadNames.get(threadId, thd.name)
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
158 d["broken"] = thd.isBroken
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
159 d["except"] = thd.isException
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
160 except Exception:
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
161 d["name"] = 'UnknownThread'
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
162 d["broken"] = False
9391a330f50f Optimized the thread list dump.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7416
diff changeset
163 d["except"] = False
5208
aa8045780ce4 Make attachThread and dumpThreadList runnable again.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5207
diff changeset
164
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
165 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
166
7283629b02c0 Relocated some methods from Debug*Thread and the remaining modules into a new one.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
167 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
168 "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
169 "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
170 })
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
171
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
172 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
173 """
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 Public method to return the currently executed 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
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 @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
177 @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
178 @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
179 @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
180 """
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 # 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
182 # 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
183 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
184 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
185 if not baseName.startswith(
5581
f8abf5f741ef Don't update currentFrame when in a breakpoint or exception. Otherwise unpredictable frames could be shown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5580
diff changeset
186 ('DebugClientBase.py', 'DebugBase.py', 'AsyncFile.py',
f8abf5f741ef Don't update currentFrame when in a breakpoint or exception. Otherwise unpredictable frames could be shown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5580
diff changeset
187 'ThreadExtension.py')):
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
188 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
189 frame = frame.f_back
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
190
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 return 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
192
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
193 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
194 """
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
195 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
196 """
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 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
198 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
199 # skip our own timer thread
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 if frame.f_code.co_name == '__eventPollTimer':
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
201 continue
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
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
203 # 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
204 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
205 newThread = DebugBase(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
206 name = 'Thread-{0}'.format(self.threadNumber)
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
207 self.threadNumber += 1
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
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5581
diff changeset
209 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
210 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
211 self.threads[threadId] = newThread
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
212
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 # 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
214 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
215 # 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
216 currentFrame = self.getExecutedFrame(frame)
5581
f8abf5f741ef Don't update currentFrame when in a breakpoint or exception. Otherwise unpredictable frames could be shown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5580
diff changeset
217 if (currentFrame is not None and
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5581
diff changeset
218 self.threads[threadId].isBroken is False):
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5581
diff changeset
219 self.threads[threadId].currentFrame = currentFrame
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
220
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
221 # Clean up obsolet because terminated 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
222 self.threads = {id_: thrd for id_, thrd in self.threads.items()
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
223 if id_ in 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
224
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
225 #######################################################################
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
226 ## 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
227 ## 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
228 #######################################################################
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
229
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
230 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
231 """
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
232 Public method to patch Python _thread (Python3) and thread (Python2)
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 modules.
5228
4332a6751b14 Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5222
diff changeset
234
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
235 @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
236 @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
237 """
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
238 # 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
239 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
240 module.start_new_thread = self.attachThread
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
241
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
242 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
243 """
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
244 Public method to patch the 'greenlet' module.
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
245
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
246 @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
247 @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
248 @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
249 @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
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 # Check for greenlet.settrace
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 if hasattr(module, 'settrace'):
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 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
254 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
255 return 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
256
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
257 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
258 """
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 Public method to patch the Python threading module.
5667
86554f131048 Avoid crashes on using greenlets.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5651
diff changeset
260
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
261 @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
262 @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
263 """
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
264 # _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
265 # 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
266 _debugClient = self
5667
86554f131048 Avoid crashes on using greenlets.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5651
diff changeset
267
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
268 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
269 """
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 Bootstrap for threading, which reports exceptions correctly.
5544
5a90f78a73c9 Handling of unhandled exceptions for threading without polluting its namespace.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
271
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
272 @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
273 @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
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 newThread = DebugBase(_debugClient)
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
276 newThread.name = self.name
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
277
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
278 _debugClient.threads[self.ident] = newThread
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
279 _debugClient.dumpThreadList()
5544
5a90f78a73c9 Handling of unhandled exceptions for threading without polluting its namespace.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
280
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
281 # 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
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 sys.settrace(None)
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
290 _debugClient.dumpThreadList()
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
291
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 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
293 """
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 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
295 """
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
296 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
297 """
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
298 Constructor
6196
7135a692e43e Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6195
diff changeset
299 """
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
300 # 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
301 # 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
302 self.run = lambda s=self, run=self.run: _bootstrap(s, 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
303
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 super(ThreadWrapper, self).__init__(*args, **kwargs)
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
305
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 module.Thread = 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
307
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 # Special handling of threading.(_)Timer
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419 7639
diff changeset
309 timer = module.Timer
5544
5a90f78a73c9 Handling of unhandled exceptions for threading without polluting its namespace.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
310
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
311 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
312 """
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
313 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
314 """
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
315 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
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 Constructor
6196
7135a692e43e Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6195
diff changeset
318 """
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
319 super(TimerWrapper, self).__init__(
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 interval, function, *args, **kwargs)
5544
5a90f78a73c9 Handling of unhandled exceptions for threading without polluting its namespace.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5389
diff changeset
321
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7419 7639
diff changeset
322 module.Timer = TimerWrapper
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
323
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 # 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
325 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
326 """
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
327 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
328 """
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
329 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
330 """
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
331 Constructor
7364
bcf6b40e7790 Fixed thread creation on uninitialized threads (found in git-cola project).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7360
diff changeset
332 """
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
333 super(DummyThreadWrapper, self).__init__(*args, **kwargs)
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
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
335 module._DummyThread = DummyThreadWrapper
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
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
337 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
338 """
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
339 Public method to patch the QtCore module's QThread.
7364
bcf6b40e7790 Fixed thread creation on uninitialized threads (found in git-cola project).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7360
diff changeset
340
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
341 @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
342 @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
343 """
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 # _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
345 # 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
346 _debugClient = self
5552
313a91a38aed Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5544
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 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
349 """
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 Bootstrap for QThread, which reports exceptions correctly.
7364
bcf6b40e7790 Fixed thread creation on uninitialized threads (found in git-cola project).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 7360
diff changeset
351
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
352 @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
353 @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
354 """
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 global _qtThreadNumber
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 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
358 ident = _thread.get_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
359 name = 'QtThread-{0}'.format(_qtThreadNumber)
5228
4332a6751b14 Support for debugging of QThread processes added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5222
diff changeset
360
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
361 _qtThreadNumber += 1
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
362
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
363 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
364 newThread.name = name
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
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
366 _debugClient.threads[ident] = newThread
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
367 _debugClient.dumpThreadList()
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
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
369 # 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
370 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
371 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
372 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
373 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
374 # *.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
375 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
376 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
377 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
378 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
379 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
380 sys.settrace(None)
7416
6f899e82f9a2 Ironed out some issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7415
diff changeset
381 _debugClient.dumpThreadList()
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
382
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 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
384 """
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 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
386 """
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 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
388 """
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
389 Constructor
5552
313a91a38aed Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5544
diff changeset
390 """
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
391 # 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
392 # intercept the thread creation by Qt
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 self.run = lambda s=self, run=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
394 _bootstrapQThread(s, run))
5552
313a91a38aed Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5544
diff changeset
395
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
396 super(QThreadWrapper, self).__init__(*args, **kwargs)
5552
313a91a38aed Handling of unhandled exceptions for *.QThread. Namespace is clean now.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5544
diff changeset
397
7415
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
398 class QRunnableWrapper(module.QRunnable):
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
399 """
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
400 Wrapper class for *.QRunnable.
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
401 """
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
402 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
403 """
7415
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
404 Constructor
6196
7135a692e43e Some code style changes and regeneration of source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6195
diff changeset
405 """
7415
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
406 # Overwrite the provided run method with our own, to
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
407 # intercept the thread creation by Qt
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
408 self.run = lambda s=self, run=self.run: (
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
409 _bootstrapQThread(s, run))
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
410
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
411 super(QRunnableWrapper, self).__init__(*args, **kwargs)
5209
cd058aa6af37 Insert import hook to modify thread module to use our bootstrap.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 5208
diff changeset
412
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
413 module.QThread = QThreadWrapper
7415
e953b2a449a9 Merged with default branch.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7412 7413
diff changeset
414 module.QRunnable = QRunnableWrapper

eric ide

mercurial