2

I have a unittest that does a bunch of stuff in several different threads. When I stop everything in the tearDown method, somehow something is still running. And by running I mean sleeping. I ran the top command on the python process (Ubuntu 12.04), which told me that the process was sleeping.

Now I have tried using pdb to figure out what is going on, e.g. by putting set_trace() at the end of tearDown. But that tells me nothing. I suspect this is because some other thread has started sleeping earlier and is therefore not accessed anymore at this point.

Is there any tool or method I can use to track down the cause of my non-stopping process?

EDIT

Using ps -Tp <#Process> -o wchan I now know that 4 threads are still running, of which three waiting on futex_wait_queue_me and one on unix_stream_data_wait. Since I had a subprocess previously, which I killed with os.kill(pid, signal.SIGKILL), I suspect that the Pipe connection is somehow still waiting for that process. Perhaps the fast mutexes are waiting for that as well.

Is there anyway I could further reduce the search space?

Vincent Ketelaars
  • 1,069
  • 1
  • 14
  • 35

1 Answers1

1

If you are working under Linux then you should be able to use 'ps -eLf' to get a list of all active processes and threads. Assuming your have given your threads good names at creation it should be easy to see what is still running.

I believe under windows you can get a tool to do something similar - see http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

N.B. I have not used the windows tool this myself

Also from within Python you can use the psutil package (https://pypi.python.org/pypi/psutil/) to get similar infomration

Tommy
  • 622
  • 5
  • 8
  • Thank you! This has helped definitely helped me :) Using ps and some other arguments (e.g. -p for the exact process) I have found wchan (waiting or sleeping on something) values for 4 threads. They seem to be a general wait and futex_wait_queue_me so far as I understand. I have not been able to link them to thread names yet though. – Vincent Ketelaars Dec 16 '13 at 16:03
  • 1
    If you use threading.enumerate() at the end of you script (at the teardown method) you should be able to get a list of all still running threads. If they are named then you should be able to identify which ones are still running. You can name a thread by passing the name="name" argument into the constructor of the threadable.thread object you use to create it. – Tommy Dec 16 '13 at 23:57
  • thanks to you I found out pretty quickly that I had a problem with a connection still being open after killing a child process. Problem solved :) – Vincent Ketelaars Dec 17 '13 at 08:33
  • I just found this post, which I found very useful for figuring out what different threads are doing: http://stackoverflow.com/a/7317379/1444854 – Vincent Ketelaars Dec 19 '13 at 10:43