New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe #70559
Comments
The initiate_send() method in both asynchat.async_chat and asyncore.dispatcher_with_send is not a thread-safe function, but it can be called from multiple threads. For example if asyncore.loop() runs in a background thread, and the main thread sends a message then both threads will call this. It can result in sending (part of) the message multiple times or not sending part of it. Possible solution: |
asynchat is now deprecated in favor of asyncio. Almost all asyncio functions are not thread-safe, it's now well documented, see the general info: If we do something, I suggest to only touch asynchat doc to explain well that asyncore and asynchat are not thread-safe. |
I don't believe the original issue is a bug. There is nothing in the docs for asyncore or asynchat that suggests they would be thread-safe. |
If I want to write a TCP client which communicates back and forth with the server (both parties can send messages anytime) then it would be really easy to use it the following way: |
"If this usage is not supported (...)" You can use threads, but access concurrently asyncore/asynchat from different threads. You have to build a communicate channel between your threads using thread-safe primitive like queue.Queue. asyncio has a builtin support for that: loop.call_soon_threadsafe(). Why not using asyncio instead of having to rebuild your own implementation? |
"Why not using asyncio instead of having to rebuild your own implementation?" The issue happened with python 2.7 and we don't want that project to depend on additional libraries. |
"I think we will upgrade that project to python3 soon and will probably use asyncio then." Great :-) You may have a look at my https://pypi.python.org/pypi/sixer project, it may help :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: