[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-17 Thread STINNER Victor

STINNER Victor added the comment:

"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 :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-17 Thread NGG

NGG added the comment:

"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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-17 Thread STINNER Victor

STINNER Victor added the comment:

"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?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-17 Thread NGG

NGG added the comment:

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:
Start a background thread with asyncore.loop(), and you can send messages 
easily, and handle_read() will be called automatically whenever data is 
received.
If this usage is not supported and I understand correctly then I can only send 
messages before starting the loop or callbacks from the loop (handle_accept, 
handle_read, etc).
This seems to be a much more difficult and error-prone way (at least for 
pre-Future python versions)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-16 Thread Guido van Rossum

Guido van Rossum added the comment:

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.

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-16 Thread STINNER Victor

STINNER Victor added the comment:

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:
https://docs.python.org/dev/library/asyncio-dev.html#concurrency-and-multithreading

If we do something, I suggest to only touch asynchat doc to explain well that 
asyncore and asynchat are not thread-safe.

--
components: +asyncio
nosy: +gvanrossum, haypo, yselivanov

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26371] asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe

2016-02-16 Thread NGG

New submission from NGG:

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:
asyncore.dispatcher_with_send.out_buffer and asynchat.async_chat.producer_fifo 
should be guarded with a lock (it should be locked even in writable())

--
components: Library (Lib)
messages: 260367
nosy: ngg
priority: normal
severity: normal
status: open
title: asynchat.async_chat and asyncore.dispatcher_with_send are not thread-safe
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com