By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

This bit of code hangs Python Indefinitely

P: n/a
url_queue = Queue.Queue(256)
for subnet in subnets:
url_queue.put(subnet)

The problem is that I have 512 things to add to the queue, but my limit
is half that... whoops. Shouldn't the interpreter tell me that I'm an
idiot for trying to do this instead of just hanging? A message such as
this would be more appropriate:

"Hey fool, you told me to only accept 256 things and you're trying to
give me 512... what's up with that?"
Aug 8 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Wed, 08 Aug 2007 09:38:49 -0400, brad wrote:
url_queue = Queue.Queue(256)
for subnet in subnets:
url_queue.put(subnet)

The problem is that I have 512 things to add to the queue, but my limit
is half that... whoops. Shouldn't the interpreter tell me that I'm an
idiot for trying to do this instead of just hanging? A message such as
this would be more appropriate:

"Hey fool, you told me to only accept 256 things and you're trying to
give me 512... what's up with that?"
No because you can get some things from that queue from another thread and
then the ``for``-loop goes on. That's the typical use case for queues.

Why did you put an upper bound to the queue?

Ciao,
Marc 'BlackJack' Rintsch
Aug 8 '07 #2

P: n/a
On Aug 8, 9:38 am, brad <byte8b...@gmail.comwrote:
The problem is that I have 512 things to add to the queue, but my limit
is half that... whoops. Shouldn't the interpreter tell me that I'm an
idiot for trying to do this instead of just hanging? A message such as
this would be more appropriate:

See the docs, especially the block and timeout parameter for the put
method:

http://docs.python.org/lib/QueueObjects.html
Istvan

Aug 8 '07 #3

P: n/a
Chris Mellon wrote:
... the producer is designed to block if
the queue is full. You can use the put_nowait method to have it raise
an exception instead of blocking.
I assumed that the behavior would have been the other way around. I
should not have made that assumption.
Aug 8 '07 #4

P: n/a
Marc 'BlackJack' Rintsch wrote:
Why did you put an upper bound to the queue?
For clarity. Explicit is better than implicit, right? In our design, the
queue should only have x number of things, so why not show that? Other
than that, the limit is arbitrary and is not needed.
Aug 8 '07 #5

P: n/a
brad <by*******@gmail.comwrote:
Chris Mellon wrote:
>... the producer is designed to block if
the queue is full. You can use the put_nowait method to have it raise
an exception instead of blocking.

I assumed that the behavior would have been the other way around. I
should not have made that assumption.
You could possibly make a case that before Queue.put blocks it should check
whether the program has more than just the one thread and if not it should
raise an RTFMException.
Aug 8 '07 #6

P: n/a
brad wrote:
Marc 'BlackJack' Rintsch wrote:
>Why did you put an upper bound to the queue?

For clarity. Explicit is better than implicit, right? In our design, the
queue should only have x number of things, so why not show that? Other
than that, the limit is arbitrary and is not needed.
Yes, but you are asking a bit more of Queue.Queue than its design is
intended to provide. Normally a limit on the input side is used to allow
the scheduling of a consumer thread that will remove items, thus
allowing the producer to restart.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 8 '07 #7

P: n/a
You could possibly make a case that before Queue.put blocks it should check
whether the program has more than just the one thread and if not it should
raise an RTFMException.
Cute :-)

Aug 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.