In my gevent-based program, I've got a thread somewhere which is suck in a loop something like:
while True:
gevent.sleep(0)
How can I figure out which thread this is? Is it possible to list (and get stack traces for) the running threads?
I use this in my code to keep track greenlets that potentially block. A NodeTaskTimeout is raised when this happens. Just wrap your jobs in a Timeout or provide them with a TimeOut object.
with Timeout(90, False):
task_jobs.join()
if task_jobs:
print 'task jobs killed', task_jobs
task_jobs.kill()
if settings.DEBUG:
raise NodeTaskTimeout
This print's out the task if it hangs/blocks/takes to long. Especially nasty are those jobs that depend on each other and cause a deadlock job1 /thread -> job2/thread2 -> job3/thread3 and job/thread3 only finishes when job1 is done wich will never happen because job2 is not done and job2 is not done because of job3 is not done.. you get the idea ;)
http://www.rfk.id.au/blog/entry/detect-gevent-blocking-with-greenlet-settrace/
but you also need to put code that you suspect to be "spinning" in a with block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With