简体   繁体   中英

asynchronous I/O multiplexing (socket and inter-thread)

I would like to have a Python thread wait either for data coming from one socket (serial port, TCP/IP, etc.), or for data coming from another thread.

And I would like a portable Windows-and-Linux solution.

What I am looking for is similar to select.select() but I believe I cannot use select.select() on Windows for inter-thread communication.

Is this possible easily ?

Are you certain that it is necessary to use threads? Are you using some foreign API that requires their use?

Anyway, using Twisted, you can easily listen on any file-like portably (including serial ports and TCP sockets). Additionally, provided that you do in fact need to use threads, Twisted provides several tools for doing so. The simplest method, given your description, would be that you call reactor.callFromThread . If you want to get data back and not simply call the function in the reactor thread, Twisted provides twisted.internet.threads.blockingCallFromThread , which will block until the function in the reactor thread returns (or, if it returns a deferred, until that deferred fires).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM