-1

I want to queue

lambda : Popen(.....)

To call/wait at a later time. Then add some more to paused Popens to the queue, then consume them again and so on.

The main Queue module cares a lot about synchronization and this makes the api feel a bit weird in places. I don't care about syncing(single threaded program, Popen just do their job and throw exception on error and they don't affect the environment in any important ways(they generate files)

Should I just use a generator that I add to it at a later time. If so whats a good way to add items to generators, calling

gena = itertools.chain(gena,[item))

each time seems wastefull.

hugomg
  • 68,213
  • 24
  • 160
  • 246
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
  • Question: is the downvote because of a bad description or? – Roman A. Taycher Dec 04 '11 at 06:16
  • Lack of research. A Google search for `Python queue` returns the desired answer as the second entry, right after the Queue class. And a word search for queue in the Library Reference Manual, after hitting heapq and queue in the table of contents, finds deque in the collections section. – Dave Dec 04 '11 at 11:02
  • I tried and missed maybe because I was tired. I remembered something like "It is also possible to use a list as a queue," but use this instead from reading it some time ago but when I searched the docs before I couldn't find it again. – Roman A. Taycher Dec 04 '11 at 12:53
  • Now that I look on google the 3rd link(2nd top level link) does point to that passage. – Roman A. Taycher Dec 04 '11 at 12:56

3 Answers3

3

Yes, you can use a deque (collections.deque), which is a list that you can efficiently push and pop on either end. You could also use a list and not worry about the inefficiency since it probably doesn't matter.

  • Good ahnswer - I vill [Pump you Up](http://www.hulu.com/watch/4184/saturday-night-live-pumping-up-with-hans-and-franz) – Dave Dec 03 '11 at 17:47
3

You can use collections.deque:

from collections import deque

queue = deque()
queue.append(new) # append
current = queue.popleft() # first item
Jochen Ritzel
  • 104,512
  • 31
  • 200
  • 194
  • Good ahnswer too, [Girly Man](http://www.hulu.com/watch/4184/saturday-night-live-pumping-up-with-hans-and-franz) – Dave Dec 03 '11 at 17:48
2

Since you aren't concerned about multi-threading, the logical choice would seem to be collections.deque.

Dave
  • 3,834
  • 2
  • 29
  • 44