breakpoint can not be tracked with calling python API in a sub-thread

Jan 11, 2012 at 11:29 AM

when I call python API in main thread, breakpoint can be tracked.

when I call python API in a sub-thread created in main thread, breakpoint can not be tracked.

what's the matter?

The following is the code:

###########################################

#Program is the module I want to debug

#there is a class named TestA in Program

#when I call Test(), breakpoint can be tracked

#when I call TestThreadFirst(), breakpoint can not be tracked

###########################################

import Program
from Program import *
import threading
from threading import *

mylock = threading.RLock()


def Test():
    a = TestA()
    a.DoProcess()

class ThreadFirst(Thread):
    def __init__(self, threadname):
        Thread.__init__(self, name = threadname)

    def run(self):
        mylock.acquire()
        a = TestA()
        a.DoProcess()
        mylock.release()
       

def TestThreadFirst():
    b = ThreadFirst('ThreadFirst')
    b.start()

 

Coordinator
Jan 11, 2012 at 6:40 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jan 11, 2012 at 6:42 PM

Thanks for the report, I've opened an issue for this..  The problem is that the main thread exits, and we report the process has exited and disable debugging.  You should be able to put a raw_input() in after calling TestThreadFirst() and it be able to hit the breakpoints.  Or you could enable "Tools->Options->Python Tools->Advanced->Wait for input when process exits normally" and it'll have the same result.  I'm looking into a fix for 1.1.

Coordinator
Jan 11, 2012 at 7:25 PM

I've checked in the fix for this to 1.1 - http://pytools.codeplex.com/SourceControl/changeset/changes/cb6d73b3d189

Jan 12, 2012 at 2:44 AM
Edited Jan 12, 2012 at 2:50 AM

Thank you for your help, but my problem is not what you said,

look at the following code and my operation steps:

############
##Program.py
############
class TestA:
    m_a = 3
    m_b = 2

    def __init__(self):
        m_a = 3
        m_b = 2

    def DoProcess(self):
        a = 1
        b = 2
        c = a + b
############
##TestProgram.py
############
import Program
from Program import *
import threading
from threading import *

mylock = threading.RLock()


def Test():
    a = TestA()
    a.DoProcess()

class ThreadFirst(Thread):
    def __init__(self, threadname):
        Thread.__init__(self, name = threadname)

    def run(self):
        mylock.acquire()
        a = TestA()
        a.DoProcess()
        mylock.release()
        

def TestThreadFirst():
    b = ThreadFirst('ThreadFirst')
    b.start()
 
 

####################

Operation Steps:

1.Open file Program.py in VS2010

2.insert a breakpoint into line no 6

3.Open file TestProgram.py in Python IDLE(pythonw.exe)

4.In VS2010, "Tools->Attach to Process", attach to process pythonw.exe just opened

5.In the Python IDLE, Run Module(Press F5)

6.Input Test() then press enter,breakpoint can be tracked in VS2010

7.Input TestThreadFirst() then press enter,breakpoint can not be tracked in VS2010

What's the matter?I think main thread doesn't exit before pythonw.exe exits.

Coordinator
Jan 12, 2012 at 6:42 PM

Thanks for the additional info, the attach detail turned out to be rather important.  I can repro this now, and the issue is that we're not getting the thread creation notice when the threading module has already been imported before the attach.  I've checked in a fix - http://pytools.codeplex.com/SourceControl/changeset/changes/31a4242b9153

Jan 13, 2012 at 2:20 AM
Edited Jan 13, 2012 at 2:20 AM

Thank you for your help.

The breakpoint can be tracked in thread with the fixed version.

but when I create second thread or input another command

in main thread, the pythonw.exe is dead.

look at the following code and my operation steps:

############
##Program.py
############
class TestA:
    m_a = 3
    m_b = 2

    def __init__(self):
        m_a = 3
        m_b = 2

    def DoProcess(self):
        a = 1
        b = 2
        c = a + b
############
##TestProgram.py
############
import Program
from Program import *
import threading
from threading import *

mylock = threading.RLock()


def Test():
    a = TestA()
    a.DoProcess()

class ThreadFirst(Thread):
    def __init__(self, threadname):
        Thread.__init__(self, name = threadname)

    def run(self):
        mylock.acquire()
        a = TestA()
        a.DoProcess()
        mylock.release()
        

def TestThreadFirst():
    b = ThreadFirst('ThreadFirst')
    b.start()
 
 

####################

Operation Steps:

1.Open file Program.py in VS2010

2.insert a breakpoint into line no 6

3.Open file TestProgram.py in Python IDLE(pythonw.exe)

4.In VS2010, "Tools->Attach to Process", attach to process pythonw.exe just opened

5.In the Python IDLE, Run Module(Press F5)

6.Input Test() then press enter,breakpoint can be tracked in VS2010

7.Input TestThreadFirst() then press enter,breakpoint can be tracked in VS2010

8.Input TestThreadFirst() or Test() then press enter, pythonw.exe is dead, I can only killed the pythonw.exe in process list

What's the matter?I think something like mutex lock has not been released correctly, so the main thread is blocked by the mutex lock

Coordinator
Jan 13, 2012 at 6:49 PM

Amazingly breaking in and then resuming execution from inside of VS will cause the app to become responsive again. Still not quite sure what's going on.

Coordinator
Jan 13, 2012 at 8:27 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jan 13, 2012 at 8:35 PM

I've checked a fix into the main branch for this issue [http://pytools.codeplex.com/SourceControl/changeset/changes/6ec4cbbf2fdc] - we'll discuss whether or not to take the fix for 1.1RC.  Thanks for the report!