Fixed loosing tracing on creating new process in multiprocess debugging.

This commit is contained in:
Dmitry Trofimov
2013-03-28 19:04:16 +01:00
parent 536d12aa2a
commit 4f1a53cdc2
3 changed files with 58 additions and 44 deletions
+44 -38
View File
@@ -2,6 +2,7 @@ import os
import shlex
import sys
import pydev_log
import traceback
helpers = os.path.dirname(__file__)
@@ -16,53 +17,58 @@ def is_python(path):
return False
def patch_args(args):
pydev_log.debug("Patching args: %s"% str(args))
try:
pydev_log.debug("Patching args: %s"% str(args))
import sys
new_args = []
i = 0
if len(args) == 0:
return args
import sys
new_args = []
i = 0
if len(args) == 0:
return args
if is_python(args[0]):
if '-c' == args[1]:
import pydevd
host, port = pydevd.dispatch()
if is_python(args[0]):
if '-c' == args[1]:
import pydevd
host, port = pydevd.dispatch()
if port is not None:
args[2] = "import sys; sys.path.append('%s'); import pydevd; pydevd.settrace(host='%s', port=%s, suspend=False); %s"%(helpers, host, port, args[2])
return args
if port is not None:
args[2] = "import sys; sys.path.append('%s'); import pydevd; pydevd.settrace(host='%s', port=%s, suspend=False); %s"%(helpers, host, port, args[2])
return args
else:
new_args.append(args[0])
else:
new_args.append(args[0])
else:
pydev_log.debug("Process is not python, returning.")
return args
pydev_log.debug("Process is not python, returning.")
return args
i = 1
while i < len(args):
if args[i].startswith('-'):
i = 1
while i < len(args):
if args[i].startswith('-'):
new_args.append(args[i])
else:
break
i+=1
if args[i].endswith('pydevd.py'): #no need to add pydevd twice
return args
for x in sys.original_argv:
if sys.platform == "win32" and not x.endswith('"'):
arg = '"%s"'%x
else:
arg = x
new_args.append(arg)
if x == '--file':
break
while i < len(args):
new_args.append(args[i])
else:
break
i+=1
i+=1
if args[i].endswith('pydevd.py'): #no need to add pydevd twice
return new_args
except:
traceback.print_exc()
return args
for x in sys.original_argv:
if sys.platform == "win32" and not x.endswith('"'):
arg = '"%s"'%x
else:
arg = x
new_args.append(arg)
if x == '--file':
break
while i < len(args):
new_args.append(args[i])
i+=1
return new_args
def args_to_str(args):
quoted_args = []
+5 -3
View File
@@ -136,8 +136,8 @@ class PyDBCommandThread(PyDBDaemonThread):
if self.killReceived:
return
self.pyDb.SetTrace(None) # no debugging on this thread
if self.dontTraceMe:
self.pyDb.SetTrace(None) # no debugging on this thread
try:
while not self.killReceived:
@@ -165,7 +165,8 @@ class PyDBCheckAliveThread(PyDBDaemonThread):
self.setName('pydevd.CheckAliveThread')
def OnRun(self):
self.pyDb.SetTrace(None) # no debugging on this thread
if self.dontTraceMe:
self.pyDb.SetTrace(None) # no debugging on this thread
while not self.killReceived:
if not self.pyDb.haveAliveThreads():
try:
@@ -1351,6 +1352,7 @@ class Dispatcher(object):
self.port = port
self.client = StartClient(self.host, self.port)
self.reader = DispatchReader(self)
self.reader.dontTraceMe = False #we run reader in the same thread so we don't want to loose tracing
self.reader.run()
def close(self):
+9 -3
View File
@@ -240,6 +240,7 @@ class PyDBDaemonThread(threading.Thread):
threading.Thread.__init__(self)
self.setDaemon(True)
self.killReceived = False
self.dontTraceMe = True
def run(self):
if sys.platform.startswith("java"):
@@ -260,6 +261,11 @@ class PyDBDaemonThread(threading.Thread):
def stop(self):
_Thread_stop(self)
def stopTrace(self):
if self.dontTraceMe:
pydevd_tracing.SetTrace(None) # no debugging on this thread
#=======================================================================================================================
# ReaderThread
#=======================================================================================================================
@@ -282,7 +288,7 @@ class ReaderThread(PyDBDaemonThread):
pass
def OnRun(self):
pydevd_tracing.SetTrace(None) # no debugging on this thread
self.stopTrace()
buffer = ""
try:
@@ -351,7 +357,7 @@ class WriterThread(PyDBDaemonThread):
def OnRun(self):
""" just loop and write responses """
pydevd_tracing.SetTrace(None) # no debugging on this thread
self.stopTrace()
try:
while True:
try:
@@ -439,7 +445,7 @@ def StartClient(host, port):
sys.stderr.write("Could not connect to %s: %s\n" % (host, port))
sys.stderr.flush()
traceback.print_exc()
sys.exit(1)
sys.exit(1) #TODO: is it safe?