473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue module and Python Documentation Rant

How can one view the contents of a queue? I'd like to verify that the
queue has the same number of objects as the list that has been put into
it. Also, should one think of a queue as static or dynamic (on the put
side)? Do you put stuff in it once and then get from it until it's empty
or do you put stuff in it a bit at a time? Or, can you do both? Also,
does the queue actually get smaller as the threads feed from it or does
it stay the same size and remember what stuff has been gotten from it
already? Is this an appropriate way to create a queue of 100,000 items?

url_queue = Queue.Queue(0)
for url in urls:
url_queue.put(u rl)

<rant>

I ask all of these questions because I find the Python documentation
lacking, to say the least. Python is a most excellent language, but the
docs are horrible! IMO, one can learn more about less sane languages
such as Perl and PHP simply because their documentation is so well
done... PHP especially. Don't get me wrong, I love Python, just hate
it's documentation. For a lang that prides itself on ease of use and
newbie-friendliness, Python should be ashamed of its module documentation

</rant>

Bart
Jul 18 '05 #1
17 2248
Bart Nessux wrote:
How can one view the contents of a queue?
You are over thinking the whole thing :-)

Especially note that the Queue is intended to be used in threaded
programming (multi-producer, multi-consumer) which the doc clearly
states.
I'd like to verify that the queue has the same number of objects
as the list that has been put into it.
There is a qsize() method clearly documented. What is wrong with
that?
Also, should one think of a queue as static or dynamic (on the put
side)?
The constructor documentation clearly describes how it behaves.
You can limit the number of items in the Queue at which point
new puts will block, or you can have the default behaviour which
allows unlimited items in the queue.
Do you put stuff in it once and then get from it until it's empty
or do you put stuff in it a bit at a time?
You put items into the Queue and get items out. Each item is an
object of any type. The Queue does not split up items. For example
if you place a string into the queue, you cannot retrieve just part
of the string first and another part later. You only get the whole
string out.
Also,
does the queue actually get smaller as the threads feed from it or does
it stay the same size and remember what stuff has been gotten from it
already?
It is a classic queue in the computer science sense. Objects can be added
(via the put method) and taken off (by the get method). The size is the
number of objects in the queue. The order is FIFO (first in first out).
Contrast with a stack which is LIFO (last in is the first out).

The "staying the same size" part of your comment usually refers to
another data type known as a circular buffer (or circular queue).

I would strongly recommend getting a copy of the Python Cookbook
and reading it. The contents are also available online but the
dead tree version is a better read.
Is this an appropriate way to create a queue of 100,000 items?

url_queue = Queue.Queue(0)
for url in urls:
url_queue.put(u rl)
Yes. However in most code you are unlikely to do that. In general
you will have some code producing items, and other code consuming
them. Another thread in this group had an example. One piece of
code was producing IP addresses to scan, and a seperate piece of
code (for example a worker thread) would take one work item and
do the scanning.

Consequently the number of items would be small since you would expect
the rate at which items are produced to be a similar order of magnitude
to the rate at which they are consumed.
I ask all of these questions because I find the Python documentation
lacking, to say the least.
The documentation for this class is actually short and sweet and I
don't think it could be improved. How would you improve it?

It is however missing an example which would make things a lot clearer
especially for people who aren't used to standard programming idioms.
The tutorial is a little brief but does cover data structures:
http://docs.python.org/tut/tut.html
PHP especially.
Pretty much anyone who has done PHP in anger raves about their docs (me
included). Not only is the meta-data really good (eg which version the
item was introduced in etc), but the user contributions are what makes
the big difference. Also as far as I can tell, every single page includes
an example.

There was a discussion here about doing the Python docs in a similar fashion
(especially the user annotations) a few weeks ago. As far as I could tell,
the results were that anyone who wanted to submit changes had to do it via
SourceForge bugs and wait a fair while (months) for the changes to appear,
or construct a wiki that is seperate from the docs.
Python should be ashamed of its module documentation


The documentation is fine. It is pretty standard for docs constructed
"cathedral" style. I do wish it was more bazaar style like the PHP
ones, but I don't have the time or inclination to help put the infrastructure
in place. Do you?

Roger

Jul 18 '05 #2
Roger Binns wrote:
There is a qsize() method clearly documented. What is wrong with
that?
Where??? The documentation for the module named Queue says nothing at
all about this...

http://docs.python.org/lib/module-Queue.html
The [Python] documentation is fine.


The docs are useless. One needs a Master's in CS just to read the module
index. In general, it's far too abstract. Many have no examples for
actual *usage* at all. Read the section about classes in the tutorial...
how long can you stay awake? It's so abstract and scholarly that it
boarders on being useless.

CS is applied math. However, Python does not think of itself as being
applied, but theoretical. This is good if you're a geek with a Ph.D, but
not if you're the average sys-admin attempting to solve an every-day
problem.

Python has a great syntax for beginners and advanced users alike. One
can do sequential, procedural and OO programming with it. Also, it can
be applied to most any problem on most any platform. However, the docs
are an exercise in futility. They remind me of the circumlocution that I
read about in law school... constantly talking around things instead of
about things.

This is good if everyone is on the same high-level of knowledge, but not
for a programming language (think applied approach to problem solving)
that has tremendous potential and is touted as user friendly for
non-programmers. No wonder so many people use Perl. As bad as Perl is,
it does not have a scholarly opinion of itself and is thus approachable
and usable.

Forgive me, I'm frustrated.

Bart

Jul 18 '05 #3
Bart Nessux wrote:
Roger Binns wrote:
There is a qsize() method clearly documented. What is wrong with
that?

Where??? The documentation for the module named Queue says nothing at
all about this...

http://docs.python.org/lib/module-Queue.html


You're right... at the bottom of the page, there is a subsection.
qsize() is there. In frustration, I overlooked it.
Jul 18 '05 #4
Bart Nessux wrote:
Where??? The documentation for the module named Queue says nothing at
all about this...

http://docs.python.org/lib/module-Queue.html


You're right... at the bottom of the page, there is a subsection.
qsize() is there. In frustration, I overlooked it.


In this particular case it is because the module name and the class
within are same name. For most modules, they differ. The top page
contains an overview of the module and then the subsections/next
button take you through each of the classes provided.

Although even that style is followed in some places such as mailbox
http://docs.python.org/lib/module-mailbox.html it isn't followed in
others such as the textwrap module
http://docs.python.org/lib/module-textwrap.html

Unfortunately I don't see what you could have done to spot the
following page other than looking at the bottom. Even if you
use the CHM docs, they only point to the front page (even
for the "Queue (class)" index entry) rather than the actual
doc page for the Queue class (ie the following page).

Roger
Jul 18 '05 #5
Roger Binns wrote:
Pretty much anyone who has done PHP in anger raves about their docs (me
included). Not only is the meta-data really good (eg which version the
item was introduced in etc), but the user contributions are what makes
the big difference. Also as far as I can tell, every single page includes
an example.


Well, not everybody: I don't like the PHP documentation at all. Part of
the problem is precisely the user comments: they are unstructured by
their very nature, and you always have to read them all because it's
very much possible to miss important information on special cases etc.
if you don't. And often they contradict each other, or are written by
newbies who feel it is their duty to share their clumsy re-invention of
the wheel to the whole community.

What should be done is regularly incorporate the useful information from
the user comments in the documentation itself and then remove the user
comments. That way the useful information is collected in one place,
while it is now scattered over the documentation proper on one side and
the different user comments on the other side.

I also find it very confusing and impractical that the user comments are
sorted from newest to oldest: very often new comments are reactions to
old comments. That requires me to scroll down-up-down-up-down-up, very
frustrating. It's like top-posters on Usenet.

Actually, I like the Python documentation much better. IMO it is both
more comprehensive and does a better job of explaining the underlying
concepts. For instance, I had absolutely no trouble finding the
documentation of the Queue module and understanding its purpose and usage.

--
"Codito ergo sum"
Roel Schroeven
Jul 18 '05 #6
> The documentation is fine. It is pretty standard for docs constructed
"cathedral" style. I do wish it was more bazaar style like the PHP
ones, but I don't have the time or inclination to help put the infrastructure
in place. Do you?


I personally really like Python documentation, and very rarely have any
trouble with it. However, I think it could be improved by having a
consistent policy regarding examples. Some modules do have examples, but
many don't.

I think a policy that requires all modules to have examples, and a
consistent place for them in the documentation, would be a big help. It
doesn't have to be a sudden overhaul of everything; but a clear policy
will hopefully lead to examples slowly being added to all parts of the
docs in a year or two.

Regardless, in my experience, the Python documentation is much better that
most other documentation I have had to use. But then, I have a masters in
computer science, so I can actually understand the module index <wink>.

-param
Jul 18 '05 #7
Paramjit Oberoi wrote:
The documentation is fine. It is pretty standard for docs constructed
"cathedral" style. I do wish it was more bazaar style like the PHP
ones, but I don't have the time or inclination to help put the infrastructure
in place. Do you?

I personally really like Python documentation, and very rarely have any
trouble with it. However, I think it could be improved by having a
consistent policy regarding examples. Some modules do have examples, but
many don't.

I think a policy that requires all modules to have examples, and a
consistent place for them in the documentation, would be a big help.


I agree. It'd be nice to see examples based on how one intends to use
the language. For example, demonstrate how one might use a module in a
sequential manner for basic sys-admin scripting purposes, then show how
the same module might be used procedurally with functions to do
something larger and more complex, and finally give an example of the
most complex scenario (object oriented) in which someone like Param
might want to use a module. IMO, this would cover all the bases.

Python appeals to such a vast user base. Why not make the docs useful to
everyone regardless of their knowledge of programming concepts?

Also, the docs aren't that bad. I was just frustrated. Once I cooled
down and read harder, I figured it out.
Jul 18 '05 #8
Roger Binns wrote:
Unfortunately I don't see what you could have done to spot the
following page other than looking at the bottom.


Reading the docs more often would help. There are many different
pages that have such subsection links at the bottom, so one
should be used to it.

For the Queue module the main page is so small it really ought
to be hard to miss!

On the other hand, it would be nice if the name "Queue" in
the class Queue constructor above had a link to the Queue Objects
page as well. No doubt contributions to change the script that
generates the docs would be welcome. :-)

-Peter
Jul 18 '05 #9
Bart Nessux wrote:
Python appeals to such a vast user base. Why not make the docs useful to
everyone regardless of their knowledge of programming concepts?


Why not indeed? How much time do you have to contribute to the
improvements? (If the answer is "none right now", then you've
just answered your own question of course.)

-Peter
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2772
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place, you've >provided next to no useful (IMHO) information to >let anyone help you more than this This is about 5% of the code. Uses no locks.
29
4206
by: Paul L. Du Bois | last post by:
Has anyone written a Queue.Queue replacement that avoids busy-waiting? It doesn't matter if it uses os-specific APIs (eg WaitForMultipleObjects). I did some googling around and haven't found anything so far. Because I know someone will ask: no, the busy-waiting hasn't been a problem in my app. I'm just interested in reading the code. p
4
1519
by: Richard Townsend | last post by:
I've been experimenting putting a reference to a function into a Queue object and was wondering what actually gets put in the Queue - is it the function's code object? If I read from the Queue in a different module, it appears that I don't need to import the module that defines the function - or any module that it uses - is this generally...
25
7737
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i...
2
2562
by: SA Trygubenko | last post by:
Dear All, Python 2.4 (#1, Mar 22 2005, 21:42:42) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Queue >>> q=Queue.Queue() >>> type(q.queue) <type 'collections.deque'> >>>
0
1439
by: Michael Bayer | last post by:
Hi - i was just going through this thread: http://mail.python.org/ pipermail/python-list/2006-April/336948.html , where it is suggested that the Lock instance used by Queue.Queue should be publically configurable. I have identified another situation where a Queue can be deadlocked, one which is also alleviated by configuring the type of...
10
3784
by: John | last post by:
I want to write a code for Breadth First Traveral for Graph, which needs a queue to implement. I wonder that for such a powerful language as Python, whether there is a better and simpler implementation for a traditional FIFO queue? Thanks!
3
4355
by: Chris Lasher | last post by:
Hello, I am working with large graphs (~150,000 to 500,000 nodes) which I need decompose node-by-node, in order of a node's value. A node's value is determined by the sum of its edge weights. When a node is removed from the graph, its neighbors' values must be updated to take into account the removed edges. I was told to look for a...
9
12737
by: Martin DeMello | last post by:
I'm writing a cluster monitor, that collects information from a set of machines and logs it to a database In the interests of not hammering the db unnecessarily, I'm considering the following 1. A series of independent "monitor" threads that collect information over TCP from the cluster of machines, and write it to a queue 2. A "logger"...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.