Vincent Ketelaars
Vincent Ketelaars

Reputation: 1109

Find reason for sleeping python process

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?

Upvotes: 2

Views: 2901

Answers (1)

Tommy
Tommy

Reputation: 622

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

Upvotes: 1

Related Questions