473,324 Members | 2,193 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,324 software developers and data experts.

Threads

Hi all,

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

TIA

May 11 '06 #1
15 1140
placid wrote:
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
cv*********@mvista.com
Build and Release
MontaVista Software

May 11 '06 #2

Carl J. Van Arsdall wrote:
placid wrote:
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


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 ?


-carl

--

Carl J. Van Arsdall
cv*********@mvista.com
Build and Release
MontaVista Software


May 12 '06 #3

On May 11, 2006, at 8:02 PM, placid wrote:

Carl J. Van Arsdall wrote:
placid wrote:
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


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

May 12 '06 #4

David Reed wrote:
On May 11, 2006, at 8:02 PM, placid wrote:

Carl J. Van Arsdall wrote:
placid wrote:
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
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


thanks, this is what i was after

Dave


May 12 '06 #5
placid wrote:
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

May 12 '06 #6
Peter Otten <__*******@web.de> wrote:
placid wrote:
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()?


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
May 12 '06 #7
Dennis Lee Bieber wrote:
On 11 May 2006 17:02:51 -0700, "placid" <Bu****@gmail.com> declaimed the
following in comp.lang.python:
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


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

--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
May 12 '06 #8

Dennis Lee Bieber wrote:
On 11 May 2006 17:02:51 -0700, "placid" <Bu****@gmail.com> declaimed the
following in comp.lang.python:

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?


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
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/


May 12 '06 #9
placid enlightened us with:
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


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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 12 '06 #10

Sybren Stuvel wrote:
placid enlightened us with:
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


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!

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa


May 12 '06 #11
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 12 '06 #12
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.

May 12 '06 #13
On 2006-05-12, antred <Nu****@gmx.net> wrote:

Nerver knew what? Please quote for context.
Aww shoot, I never knew that!!


http://docs.python.org/lib/QueueObjects.html

get([block[, timeout]])

Remove and return an item from the queue. If optional args
block is true and timeout is None (the default), block if
necessary until an item is available. [...]

--
Grant Edwards grante Yow! VICARIOUSLY
at experience some reason
visi.com to LIVE!!
May 12 '06 #14
On 2006-05-12, Sybren Stuvel <sy*******@YOURthirdtower.com.imagination> wrote:
placid enlightened us with:
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


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.

--
Grant Edwards grante Yow! Is this ANYWHERE,
at USA?
visi.com
May 12 '06 #15

Dennis Lee Bieber wrote:
On Fri, 12 May 2006 14:30:12 -0000, Grant Edwards <gr****@visi.com>
declaimed the following in comp.lang.python:
On 2006-05-12, Sybren Stuvel <sy*******@YOURthirdtower.com.imagination> wrote:
placid enlightened us with:
>> 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

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.


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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/


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

May 15 '06 #16

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

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
6
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.