# Deadlock in python queue module

**URL:** <https://discuss.python.org/t/deadlock-in-python-queue-module/10531>\
**Category:** Python Help\
**Created:** [September 9, 2021, 4:40am UTC](https://discuss.python.org/t/deadlock-in-python-queue-module/10531 "2021-09-09T04:40:46Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Milton\_Mobley](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@Milton\_Mobley](https://discuss.python.org/u/Milton_Mobley)\
**Post date:** [September 24, 2021, 12:09am UTC](https://discuss.python.org/t/deadlock-in-python-queue-module/10531/4 "2021-09-24T00:09:19Z")

</div>

I hope this may help:

In your original post you give only a simplified version of the code’s action.

The threads might appear to be blocked if socket.recv() and usbdev.read() are not actually producing  
messages. What data do you expect socket.recv() to produce? Same for usbdev.read(). I mean not contents, but size and frequency of messages. You could write simple programs to measure these,  
and verify the data you expect is being produced.

I looked at the Python source for the queue module. It looks pretty straightforward for queue code, and is probably not the source of the problem.

Otherwise, you could set some gdb breakpoints in the C backend code. I see that PyThread\_acquire\_lock\_timed() is implemented in the source in the file Python/thread\_pthread.h.  
Perhaps you could find some place around there to set breakpoints, in an error path that you do not expect to be taken, not the main (success) path. The semaphore get operations are supposed to time out.

Alternately, you could try to use the queues in the multiprocessing module, which use the semaphores differently.

---

_[View the full topic](https://discuss.python.org/t/deadlock-in-python-queue-module/10531)._
