python - multithreading - overwrite old value in queue? -
i have 2 threads: producer , consumer. producer periodically acquires information , provides consumer. consumer wants current copy of information , check aperiodically , maybe long intervals.
it seems simplest mechanism facilitate communication create queue.queue(maxsize=1)
. however, if producer acquires new information before old information consumed block until consumer uses out of date information first. there way producer overwrite old information?
is there better threadsafe mechanism accomplish this?
the simplest fix let producer consume old value, if there one, before putting. can use queue.get_nowait()
this.
stylistically, i'm not keen on using queue ever intended hold 1 object. normal lock + reference variable make more obvious code does.
Comments
Post a Comment