简体   繁体   中英

Send a string to another python thread

I need to send strings to a separate thread asynchronously (meaning no one knows when). I am using threading because my problem is IO bound.

My current best bet is set a flag and have the receiver thread poll that. When it detects a set flag it reads from some shared memory .

This sounds horribly complicated. Can't I send messages via a mailbox ? Or something even better like implicit variable semantics?

The queue.Queue class is ideal for this. Your thread can either block waiting for input, or it can check whether anything new has arrived, and it is thread-safe.

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