Threads

P

placid

Hi all,

In Python, Threads cannot be paused, i remember reading this somewhere,
so is there a way around this ?

TIA
 
C

Carl J. Van Arsdall

placid said:
Hi all,

In Python, Threads cannot be paused, i remember reading this somewhere,
so is there a way around this ?

When you say paused do you mean paused by an external source or paused
by a call internal to the thread? There are plenty of synchronization
constructs for making threads wait: Check out Events and Conditions

-carl



--

Carl J. Van Arsdall
(e-mail address removed)
Build and Release
MontaVista Software
 
P

placid

Carl said:
When you say paused do you mean paused by an external source or paused
by a call internal to the thread? There are plenty of synchronization
constructs for making threads wait: Check out Events and Conditions

I have a thread that has a job Queue, it continuosly polls this queue
to see if there are any jobs for it, what i really wont to be able to
do is, when the queue is empty, i want the thread to pause (or more
technical, i want the thread to block) until the queue gets populated
again. Is this possible ?
 
D

David Reed

I have a thread that has a job Queue, it continuosly polls this queue
to see if there are any jobs for it, what i really wont to be able to
do is, when the queue is empty, i want the thread to pause (or more
technical, i want the thread to block) until the queue gets populated
again. Is this possible ?


The previous poster answered your question - you want to use a
condition variable.

http://docs.python.org/lib/condition-objects.html

Dave
 
P

Peter Otten

placid said:
I have a thread that has a job Queue, it continuosly polls this queue
to see if there are any jobs for it, what i really wont to be able to
do is, when the queue is empty, i want the thread to pause (or more
technical, i want the thread to block) until the queue gets populated
again. Is this possible ?

Isn't that the default behaviour of Queue.get()?

Peter
 
A

Alex Martelli

Peter Otten said:
Isn't that the default behaviour of Queue.get()?

Absolutely! placid, just call the get method of that Queue instance: if
the queue is empty your thread DOES pause, or block, until there's some
item put on the queue by another thread.


Alex
 
D

Dennis Lee Bieber

I have a thread that has a job Queue, it continuosly polls this queue
to see if there are any jobs for it, what i really wont to be able to
do is, when the queue is empty, i want the thread to pause (or more
technical, i want the thread to block) until the queue gets populated
again. Is this possible ?
Did you read the documentation for Queue methods?

x = q.get(true) #blocks until data is available
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
E

Edward Elliott

Dennis said:
Did you read the documentation for Queue methods?

x = q.get(true) #blocks until data is available

Like a good lawyer, Dennis knows the answer before he asks the question.
 
P

placid

Dennis said:
Did you read the documentation for Queue methods?

there is no need to be patronizing about this dude, im just learning
Python in my spare time, as im a Intern Software Engineer
x = q.get(true) #blocks until data is available


this is even better, thanks dude
 
S

Sybren Stuvel

placid enlightened us with:
there is no need to be patronizing about this dude, im just learning
Python in my spare time, as im a Intern Software Engineer

There is nothing patronizing about the question, it's merely an
enquiry to a possible fact. If you're going to be a techie, you should
learn stuff like that.

Sybren
 
P

placid

Sybren said:
placid enlightened us with:

There is nothing patronizing about the question, it's merely an
enquiry to a possible fact. If you're going to be a techie, you should

true enough
learn stuff like that.

its always said that (in programming) that the easiest solution to a
problem is hard to find, well for me posting my question here was the
hardest, when the easier solution was for me to go look at the Python
documentation!
 
S

Sybren Stuvel

placid enlightened us with:
its always said that (in programming) that the easiest solution to a
problem is hard to find

Yeah, that's true allright!

Sybren
 
A

antred

Aww shoot, I never knew that!! LOL, I implemented my own worker thread
class using a mutex protected job list and a pair of connected sockets
for interprocess communication when I could just have used the darn
Queue module instead. Grrrrr .... hehe.
 
G

Grant Edwards

placid enlightened us with:

There is nothing patronizing about the question, it's merely
an enquiry to a possible fact. If you're going to be a techie,
you should learn stuff like that.

It's also valuable information to the maintainers of the
documentation. If he _did_ read the documentation and still
didn't know that Queue.get() could block, then one might ask
how the documentation could be improved.
 
D

Dennis Lee Bieber

It's also valuable information to the maintainers of the
documentation. If he _did_ read the documentation and still
didn't know that Queue.get() could block, then one might ask
how the documentation could be improved.

If it means anything -- I typically do bring up the help files and
cut&paste the relevant paragraph. But I had a 24-hour backlog and it was
late at night so a straight off-the-cuff entry was made. Though I
suppose one could go back to the "smart questions" FAQ, and have
suggested the original poster tell us what documentation was read in
search of a solution prior to their post (in which case my short
response could be interpreted as a less than subtle hint to read the
references first).
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
P

placid

Dennis said:
If it means anything -- I typically do bring up the help files and
cut&paste the relevant paragraph. But I had a 24-hour backlog and it was
late at night so a straight off-the-cuff entry was made. Though I
suppose one could go back to the "smart questions" FAQ, and have
suggested the original poster tell us what documentation was read in
search of a solution prior to their post (in which case my short
response could be interpreted as a less than subtle hint to read the
references first).

telling me to read the documentation would have been a good reminder
dude!

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/

thanks again for all of you who replied with great answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,240
Latest member
เพิ่มไลค์|LikePro

Latest Threads

Top