Re: Threading / Queue management

2009-02-09 Thread Aahz
In article a852a388-2e3f-4b45-aa80-695fc116e...@v18g2000pro.googlegroups.com,
Power Button  mjbuc...@gmail.com wrote:

I wonder if anyone can help with the following. I have written a
script which polls a server and if it finds and pending orders, it
instantiates an new object (foo) - in a new thread and processes some
data. In the new object (foo), there are also some long running
processes so I am trying to create a thread pool/queue and to push
items onto the queue in the instantiated object (foo). Currently I am
creating the Queue in foo but this means I am starting up 5 new
threads every time I instantiate foo. What I want to be able to do is
create the Queue and start 5 (n) threads when my program starts and
then push items onto the queue in foo.

Not sure what you're trying to do, but you meay find this sample code
useful:

http://www.pythoncraft.com/OSCON2001/index.html
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading / Queue management

2009-02-03 Thread Hendrik van Rooyen
 Power Button mjbuc...@gmail.com

 My question is, how can I create the Queue in my main object and set
 the target function for the Thread Constructor to be a function in
 foo?

Just create it, giving it some name.
Then start the static long running stuff,
and pass the name you gave it.

Pass the name to the thing that starts the 
per transaction thread, so that it can pass
it to the new thread, and away you go.

You may even need an output queue, so that 
the static long running stuff knows what to do 
with the results, and a thread to handle the
final output.

- Hendrik


--
http://mail.python.org/mailman/listinfo/python-list


Re: Threading / Queue management

2009-02-02 Thread Steve Holden
Power Button wrote:
 hi there,
 
 I wonder if anyone can help with the following. I have written a
 script which polls a server and if it finds and pending orders, it
 instantiates an new object (foo) - in a new thread and processes some
 data. In the new object (foo), there are also some long running
 processes so I am trying to create a thread pool/queue and to push
 items onto the queue in the instantiated object (foo). Currently I am
 creating the Queue in foo but this means I am starting up 5 new
 threads every time I instantiate foo. What I want to be able to do is
 create the Queue and start 5 (n) threads when my program starts and
 then push items onto the queue in foo.
 
 My question is, how can I create the Queue in my main object and set
 the target function for the Thread Constructor to be a function in
 foo?
 
This might help.

http://www.chrisarndt.de/projects/threadpool/

If not, Google around for Python threadpool. If that doesn't help
either, come back to the list.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list