Queues - Is Infinity all right?
Peter Hansen
peter at engcorp.com
Mon Oct 6 21:07:28 EDT 2003
Anand Pillai wrote:
>
> This was exactly what my problem was. The producer thread was
> creating a lot of data to the queue which the consumer cannot
> keep up with.
>
> Since I am using python threads, it so happens most of the time
> that the queue is filled to huge sizes, and the consumer thread
> context switch is not done, causing memory problems.
>
> I have not gone through the code of Queue.py, but I think that
> the queue.get() method is an O(n) operation, considering the
> ration of 'put's to the 'get's.
I think you might be misinterpreting things. Remember that put()
and get() on a list are actually implemented in C code, so relative
to anything you would actually do with the data that you get(),
and to anything you actually do in order to produce the data that
you put(), the actual put() and get() operations are effectively
both instantaneous (and thus in effect O(1)) unless you are talking
literally thousands of items in the Queue.
And you seem to be suggesting it is because get() is O(n) that you
are even getting to this overload point, but the time for the get()
won't become noticeable until you've already had a problem for
quite some time.
-Peter
More information about the Python-list
mailing list