473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading modeule and condition??

System is Mandrake-9.1 with Python-2.3.4

I need to learn condition variables (mentioned in Section 7.5.3 of library
reference) but I am confused on the way of creating one. The documentation
says:
---
# Produce one item
cv.acquire()
make_an_item_av ailable()
cv.notify()
cv.release()

To choose between notify() and notifyAll(), consider whether one state
change can be interesting for only one or several waiting threads. E.g. in
a typical producer-consumer situation, adding one item to the buffer only
needs to wake up one consumer thread.

class Condition([lock])

If the lock argument is given and not None, it must be a Lock or RLock
object, and it is used as the underlying lock. Otherwise, a new RLock object
is created and used as the underlying lock.
---

how do I insttantiate 'cv' the condition object in the first place. A code
fragment will be helpful.

-ishwar
Jul 18 '05 #1
4 1073
On 23 Jul 2004, Ishwar Rattan wrote:
how do I insttantiate 'cv' the condition object in the first place. A code
fragment will be helpful.

from threading import Condition cv = Condition()


Just like any object ;)

Just make sure you do this _before_ creating your threads, so that the
object is shared by all the threads when they are created.

Jul 18 '05 #2
Christopher T King <sq******@WPI.E DU> writes:
Just make sure you do this _before_ creating your threads, so that the
object is shared by all the threads when they are created.


Order of creation shouldn't make any difference. Condition objects
(as all of the synchronization objects built on top of the lock
primitive) exist independent of thread's per-se. They are designed
for use from multiple-threads, so it doesn't matter if they are
created before or after the threads that use them, although obviously
you need to hand the threads references to the objects they are going
to use.

-- David
Jul 18 '05 #3
On 23 Jul 2004, David Bolen wrote:
Christopher T King <sq******@WPI.E DU> writes:
Just make sure you do this _before_ creating your threads, so that the
object is shared by all the threads when they are created.


Order of creation shouldn't make any difference. Condition objects
(as all of the synchronization objects built on top of the lock
primitive) exist independent of thread's per-se. They are designed
for use from multiple-threads, so it doesn't matter if they are
created before or after the threads that use them, although obviously
you need to hand the threads references to the objects they are going
to use.


That's more what I was getting at, "make sure you create one and pass it
to all your threads instead of creating different ones in each thread".
Poor wording on my part.

Jul 18 '05 #4
In article <93************ **************@ posting.google. com>,
Ishwar Rattan <ra****@cps.cmi ch.edu> wrote:

I need to learn condition variables (mentioned in Section 7.5.3 of library
reference) but I am confused on the way of creating one.


Right. That's why you don't use conditions. Use Queue.Queue instead.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"To me vi is Zen. To use vi is to practice zen. Every command is a
koan. Profound to the user, unintelligible to the uninitiated. You
discover truth everytime you use it." --*****@lion.aust in.ibm.com
Jul 18 '05 #5

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

Similar topics

19
6446
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread...
0
1517
by: Jacek Trzmiel | last post by:
Hi, I have a problem with using urllib2 with threading module under Cygwin. $ cygcheck -cd cygwin python Cygwin Package Information Package Version cygwin 1.5.5-1 python 2.3.2-1
0
1317
by: Mark English | last post by:
Every once in a while since I moved to Python 2.4 I've been seeing the following exception in threading.py Condition: File "mctest3.py", line 1598, in WaitForMessages self.condResponses.wait(1.0) File "C:\Program Files\Python24\lib\threading.py", line 221, in wait delay = min(delay * 2, remaining, .05) OverflowError: long int too large to...
3
3218
by: Peter Hansen | last post by:
I'm still trying to understand the behaviour that I'm seeing but I'm already pretty sure that it's either a bug, or something that would be considered a bug if it didn't perhaps avoid even worse behaviour. Inside the join() method of threading.Thread objects, a Condition named self.__block is acquired, and then the wait logic is executed. ...
6
2842
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things,...
2
13165
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using System.Timers.Timer but i had to remove it because of known bug(842739). Now i am using System.Threading.Timer. It executes routine fine but the...
2
2058
by: akameswaran | last post by:
Admittedly this problem causes no actual functional issues aside from an occasional error message when the program exits. The error is: Unhandled exception in thread started by Error in sys.excepthook: Original exception was: Yes all that info is blank. The application is a console application that is waiting for some condition on the...
4
1643
by: daniel | last post by:
Hello, Can anyone explain the main points in working with threads in Python. Why use threading and not Thread.I have read an article that i have to subclass the Thread class and override some function.
126
6640
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard: http://www.cse.wustl.edu/~schmidt/ACE.html the same way that the STL (and subsequently BOOST) have been subsumed? Since it already runs on zillions of platforms, they have...
0
7689
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
7943
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...
0
7786
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...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5359
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
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
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.