473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

This bit of code hangs Python Indefinitely

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
7 1004
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ywsat | last post by:
Has anyone experienced the problem where PythonWin debugger hangs you stop the debug session? I'm running Windows 2000. Python 2.3. I have to kill it through the task manager each time. ...
0
by: Nowan | last post by:
Hi, I'm running Win 2K Pro Apache 1.3 (IBM version, starting manually, not a service) Spyce 1.3.11 (latest version) Python 2.2.2 (ActiveState) Everything installed as an administrator.
11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
12
by: JD | last post by:
This is another Python problem, I think might be unrelated to the earlier bug I found, and eventually figured out how to report it to Sourceforge. This is related to a question I have about...
44
by: Bamber | last post by:
Why does f get returned ? (compiled with gcc). #include<stdio.h> int func(int a); main() { int f; f=func(7); printf("f=%d",f);
105
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
18
by: Wiktor Zychla [C# MVP] | last post by:
Following code was supposed to sort an ArrayList of strings while keeping one "fixed" element at the last position. However, the code hangs in .NET 1.1. I think that answering these questions...
4
by: emin.shopper | last post by:
Emacs seems to freeze when doing certain shell commands on Microsoft Windows. The following is a simple example with Xemacs: ---------------------------------------------------------- ...
5
by: silverburgh.meryl | last post by:
Hi, I have the following regular expression. It works when 'data' contains the pattern and I see 'match2' get print out. But when 'data' does not contain pattern, it just hangs at 're.findall'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.