Multi-threading usually means locking critical sections, etc. So I can’t help but wonder, in a single-threaded program or a multi-threaded program but where the queue is just used in one particular thread, is there some (unnecessary) locking type of overhead?
For instance when you call put or get or qsize, etc, does it lock then do some processing then release the lock?
Locks are hard-coded into the Queue class. Thus, the methods
put,getwill use locks no matter how many threads exist in your program. The Queue is a module used to facilitate communications between threads.Check
Queue.py‘s implementationAnd its
putmethod:I hope this answers your question.
UPDATE:
Even the method
qsizeuses locks:FYI, i checked
Queue.py‘s implementation forPython2.7