简体   繁体   中英

Python - threaded pyinotify output. Better to write to file or to a string

I have a pyinotify watcher running threaded, called as a separate class, at the moment it just prints its discoveries in a terminal window, if I wanted my script to make an action based on those changes am I better to:

A) modify an array with each notification

B) write to a file in /tmp and fetch it from my main script?

c) give up programming

thanks for any input,

Stewart

import Queue
changes = Queue.Queue()

and now use changes.put in the thread that discover the changes, changes.get in the thread that is supposed to act on those changes (there are several other useful methods in Queue that you should check -- also note, per the docs, that the module's renamed to queue , all lowercase, in Python 3). Queues are intrinsically thread-safe and therefore often the best way to arrange cooperation among threads in Python.

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