Closed tomprimozic closed 4 months ago
There shouldn't be a deadlock with the mutex there. The mutex is to prevent multiple threads from sending messages at the same time.
Do you believe you are seeing this for async or threaded client? If it's for the async, this https://github.com/deepgram/deepgram-python-sdk/issues/301 is potentially a known issue that might appear to cause this. Do you have logs that we can look at?
I added a minimal reproducible example.
The deadlock happens when there's an exception raised by the self._socket.send(...)
method, because the socket has already been closed.
The with ...:
statement will release the lock even in case of exceptions (similar to a finally:
block).
Thanks for reporting the issue with the example! That was super helpful! I appreciate it a ton!
This should address the issue without removing the send mutex: https://github.com/deepgram/deepgram-python-sdk/pull/306
Sure but you should still make this change. This code
lock.acquire()
do_something_that_might_cause_an_exception()
lock.release()
is just wrong (see Python official docs here).
Also, your PR further complicates the algorithm, and doesn't even use locks properly!
(Also, my code doesn't remove the send mutex, it just uses it correctly.)
Ahhhh shoot.... flipping back and forth between languages is really messing with me. You are right.
EDIT: Let me re-think the exception cases though something still isn't right with it.
Thanks for your PR!
Proposed changes
Manage multi-threaded resources with Python's built-in syntax, to avoid deadlocks.
Types of changes
What types of changes does your code introduce to the community Python SDK? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
minimal reproducible example:
output: