Issue 595217: asynchat problems multi-threaded (original) (raw)

asynchat.async_chat.push has two problems when used in an application where the pusher and the main loop are run by different threads.

  1. A "push" does not wake up the main loop. This may result in long delays (the loop, by default, uses a timeout of 30 s). The work around is an explicit wakeup on the loop. I do not have a solution for Windows (more generally an OS where select does not work for pipes). When select does work for pipes, a simple "wakeup" can be implemented by writing to a pipe the main loop is waiting for.

  2. The "self.initiate_send" can lead to two identical sends (which should be only one!) under the condition above. Workaround is to remove the call.