1

I'm debugging a multi-threaded Python program with Wing IDE.

When I press the pause button, it pauses only one thread. I've tried it ten times and it always pauses the same thread, in my case called "ThreadTimer Thread", while the other threads keep on running. I want to pause these other threads so I could step with them. How do I do that?

3 Answers 3

1

I don't know if multi-thread debugging is possible with Wing IDE.

However you maybe interested in Winpdb which has this capability

Sign up to request clarification or add additional context in comments.

2 Comments

From the Wing doc: "Wing's debugger provides a powerful toolset for rapidly locating and fixing bugs in single-threaded or multi-threaded Python code." Unfortunately I couldn't find the answer to my question in the documentation.
I checked out Winpdb, it's great!
1

Per the docs, all threads that are running Python code are stopped (by default, i.e., unless you're going out of the way to achieve a different effect). Are the threads that you see as not getting stopped running non-Python code (I/O, say: that gives its own issues), or are you doing something else than running in a pristine install without the tweaks the docs describe to only pause some of the threads...?

6 Comments

It's a pristine install, but I was working in wxPython. Does that mean I cannot stop the wxPython thread?
I believe you can't stop the GUI tread (that would make the whole GUI unresponsive) if I correctly understand what you mean.
I don't mean the GUI thread of Wing, I mean the GUI of my program. What's the problem with making it unresponsive?
Oh, I misread you. As long as it's running Python code at the time you request the thread stop (as opposed to the abundant C++ code making up the bulk of wxWidgets/wxPython) it should stop, GUI or no GUI.
Your mention of wxPython reminds me of the docs found at wingware.com/doc/howtos/wxpython -- I assume you can debug their supplied demo.py w/o problems; what if you tweak it to add some minimal threading, can you reproduce your issue very simply?
|
0

I just name my threads when I create them.

Example thread:

import threading
from threading import Thread

#...
client_address = '192.168.0.2'
#...

thread1 = Thread(target=thread_for_receiving_data,
                         args=(connection, q, rdots),
                         name='Connection with '+client_address,
                         daemon=True)
thread1.start()

Then you can always access the name from inside the thread

print(threading.currentThread())
sys.stdout.flush() #this is essential to print before the thread is completed

You can also list all threads with a specific name

for at in threading.enumerate():
    if at.getName().split(' ')[0] == 'Connection':
        print('\t'+at.getName())

A similar thing can be done to a process.

Example process:

import multiprocessing


process1 = multiprocessing.Process(target=function,
                         name='ListenerProcess',
                         args=(queue, connections, known_clients, readouts),
                         daemon=True)
process1.start()

With processes it is even better as you can terminate a specific process by its name from outside of it

for child in multiprocessing.active_children():
    if child.name == 'ListenerProcess':
        print('Terminating:', child, 'PID:', child.pid)
        child.terminate()
        child.join()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.