Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to
sleep. How to do this?
thanks
mark
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff''' 11 1898
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to
sleep. How to do this?
thanks
mark
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html )
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Cheers
On 20 Feb 2007 20:47:57 -0800, placid <Bu****@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html )
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark
To set the event object
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandler.start()
# do something here #
evtHandler.event.set()
# do more stuff here #
evtHandler.event.set()
</code>
Hope thats what your looking for.
Cheers
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event (
>http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark
To set the event object
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandler.start()
# do something here #
evtHandler.event.set()
# do more stuff here #
evtHandler.event.set()
</code>
Hope thats what your looking for.
Cheers
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
On 20 Feb 2007 21:26:18 -0800, placid <Bu****@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event (
>http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
I don't think a thread can block on more than one event at a time. But
you can make it block on more then one event one at a time.
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.events = [threading.Event(), threading.Event()]
self.currentEvent = None
def run:
while True:
for event in self.events:
self.currentEvent = event
# block until some event happens
self.currentEvent.wait()
""" do stuff here """
self.currentEvent.clear()
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
what the thread does is sequentially waits for two events to happen
and then execute the same code. You could change this code to perform
different functions for different event objects.
Cheers
On 21 Feb 2007 14:47:50 -0800, placid <Bu****@gmail.comwrote:
On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
I don't think a thread can block on more than one event at a time. But
you can make it block on more then one event one at a time.
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.events = [threading.Event(), threading.Event()]
self.currentEvent = None
def run:
while True:
for event in self.events:
self.currentEvent = event
# block until some event happens
self.currentEvent.wait()
""" do stuff here """
self.currentEvent.clear()
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
what the thread does is sequentially waits for two events to happen
and then execute the same code. You could change this code to perform
different functions for different event objects.
Once the thread starts it is going to wait on the event that is the
first element of the list right? This would mean :
evtHandlerThread.currentEvent.set(): that I have only one event right?
Can you explain how I can have different event objects. I dont see how
I can do different functinos for same event.
Thanks a lot!
mark
On Feb 22, 10:20 am, mark <rkmr...@gmail.comwrote:
On 21 Feb 2007 14:47:50 -0800, placid <Bul...@gmail.comwrote:
On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event (
>http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
I don't think a thread can block on more than one event at a time. But
you can make it block on more then one event one at a time.
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.events = [threading.Event(), threading.Event()]
self.currentEvent = None
def run:
while True:
for event in self.events:
self.currentEvent = event
# block until some event happens
self.currentEvent.wait()
""" do stuff here """
self.currentEvent.clear()
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
what the thread does is sequentially waits for two events to happen
and then execute the same code. You could change this code to perform
different functions for different event objects.
Once the thread starts it is going to wait on the event that is the
first element of the list right? This would mean :
This is correct.
evtHandlerThread.currentEvent.set(): that I have only one event right?
this means that the current event occurred.
Can you explain how I can have different event objects. I dont see how
I can do different functinos for same event.
Thanks a lot!
mark
To run different functions for the same event is easy, just write a
wrapper class around threading.event() and include some method that
you will run and assign this to different functions for each
EventWrapper.
<code>
class EventWrapper():
def __init__(self,work ):
self.event = threading.Event()
self.eventWork = work
def wait(self):
self.event.wait()
def clear(self)
self.event.clear()
def eventWork(self):
print "no work"
class eventhandler(threading.Thread):
def __init__(self, events = None):
threading.Thread.__init__(self)
self.events = events
self.currentEvent = None
def run:
while True:
if self.events:
for event in self.events:
self.currentEvent = event
# block until the current event happens
self.currentEvent.wait()
self.currentEvent.eventWork()
self.currentEvent.clear()
def eventOneWork():
# do some event 1 specific work here
def eventTwoWork():
# do some event 2 specific work here
if __name__ == "__main__":
events = [EventWrapper(eventOneWork),EventWrapper(eventTwoWo rk)]
evtHandlerThread = eventhandler(events)
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
So you have a EventWrapper class that now contains the Event object
and a workEvent() method which is assigned to a function you create.
Hope this helps.
Cheers
On 21 Feb 2007 16:10:51 -0800, placid <Bu****@gmail.comwrote:
On Feb 22, 10:20 am, mark <rkmr...@gmail.comwrote:
On 21 Feb 2007 14:47:50 -0800, placid <Bul...@gmail.comwrote:
On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event ( http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
I don't think a thread can block on more than one event at a time. But
you can make it block on more then one event one at a time.
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.events = [threading.Event(), threading.Event()]
self.currentEvent = None
def run:
while True:
for event in self.events:
self.currentEvent = event
# block until some event happens
self.currentEvent.wait()
""" do stuff here """
self.currentEvent.clear()
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
what the thread does is sequentially waits for two events to happen
and then execute the same code. You could change this code to perform
different functions for different event objects.
Once the thread starts it is going to wait on the event that is the
first element of the list right? This would mean :
This is correct.
evtHandlerThread.currentEvent.set(): that I have only one event right?
this means that the current event occurred.
Can you explain how I can have different event objects. I dont see how
I can do different functinos for same event.
Thanks a lot!
mark
To run different functions for the same event is easy, just write a
wrapper class around threading.event() and include some method that
you will run and assign this to different functions for each
EventWrapper.
<code>
class EventWrapper():
def __init__(self,work ):
self.event = threading.Event()
self.eventWork = work
def wait(self):
self.event.wait()
def clear(self)
self.event.clear()
def eventWork(self):
print "no work"
class eventhandler(threading.Thread):
def __init__(self, events = None):
threading.Thread.__init__(self)
self.events = events
self.currentEvent = None
def run:
while True:
if self.events:
for event in self.events:
self.currentEvent = event
# block until the current event happens
self.currentEvent.wait()
self.currentEvent.eventWork()
self.currentEvent.clear()
def eventOneWork():
# do some event 1 specific work here
def eventTwoWork():
# do some event 2 specific work here
if __name__ == "__main__":
events = [EventWrapper(eventOneWork),EventWrapper(eventTwoWo rk)]
evtHandlerThread = eventhandler(events)
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
So you have a EventWrapper class that now contains the Event object
and a workEvent() method which is assigned to a function you create.
THanks a lot! Does this have to have event1 and event2 occur in
sequence? Will this still work even if only event2 occurs and event1
never occurs?
thanks
mark
On Feb 22, 12:08 pm, mark <rkmr...@gmail.comwrote:
On 21 Feb 2007 16:10:51 -0800, placid <Bul...@gmail.comwrote:
On Feb 22, 10:20 am, mark <rkmr...@gmail.comwrote:
On 21 Feb 2007 14:47:50 -0800, placid <Bul...@gmail.comwrote:
On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote:
On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote:
On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote:
On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and go back to sleep
class eventhndler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(SLEEPTIME)
''''do event stuff'''
The way i would do this is by using an threading.Event (
>http://docs.python.org/lib/event-objects.html)
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run:
while True:
# block until some event happens
self.event.wait()
""" do stuff here """
self.event.clear()
</code>
the way to use this is to get the main/separate thread to set() the
event object.
Can you give an example of how to get the main threead to set teh event object?
this is exactly what i wanted to do!
thanks a lot!
mark>
oops I've miss-typed the thread variable name the following should
work
<code>
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.event.set()
# do more stuff here #
evtHandlerThread.event.set()
</code>
Can I have the same thread process two or more events? Can you tell
how to do this? The code you gave is waiting on one event right. How
can I do it for more events?
thanks a lot!
mark
I don't think a thread can block on more than one event at a time. But
you can make it block on more then one event one at a time.
<code>
class eventhandler(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.events = [threading.Event(), threading.Event()]
self.currentEvent = None
def run:
while True:
for event in self.events:
self.currentEvent = event
# block until some event happens
self.currentEvent.wait()
""" do stuff here """
self.currentEvent.clear()
if __name__ == "__main__":
evtHandlerThread = eventhandler()
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
what the thread does is sequentially waits for two events to happen
and then execute the same code. You could change this code to perform
different functions for different event objects.
Once the thread starts it is going to wait on the event that is the
first element of the list right? This would mean :
This is correct.
evtHandlerThread.currentEvent.set(): that I have only one event right?
this means that the current event occurred.
Can you explain how I can have different event objects. I dont see how
I can do different functinos for same event.
Thanks a lot!
mark
To run different functions for the same event is easy, just write a
wrapper class around threading.event() and include some method that
you will run and assign this to different functions for each
EventWrapper.
<code>
class EventWrapper():
def __init__(self,work ):
self.event = threading.Event()
self.eventWork = work
def wait(self):
self.event.wait()
def clear(self)
self.event.clear()
def eventWork(self):
print "no work"
class eventhandler(threading.Thread):
def __init__(self, events = None):
threading.Thread.__init__(self)
self.events = events
self.currentEvent = None
def run:
while True:
if self.events:
for event in self.events:
self.currentEvent = event
# block until the current event happens
self.currentEvent.wait()
self.currentEvent.eventWork()
self.currentEvent.clear()
def eventOneWork():
# do some event 1 specific work here
def eventTwoWork():
# do some event 2 specific work here
if __name__ == "__main__":
events = [EventWrapper(eventOneWork),EventWrapper(eventTwoWo rk)]
evtHandlerThread = eventhandler(events)
evtHandlerThread.start()
# do something here #
evtHandlerThread.currentEvent.set()
# do more stuff here #
evtHandlerThread.currentEvent.set()
</code>
So you have a EventWrapper class that now contains the Event object
and a workEvent() method which is assigned to a function you create.
THanks a lot! Does this have to have event1 and event2 occur in
sequence? Will this still work even if only event2 occurs and event1
never occurs?
thanks
mark
well if event1 never occurs then it will block/wait until forever and
even if event2 has occurred you never know about it until event1
occurs. You can introduce a timeout to the wait() call on the event
object which says, "block X seconds or until event happens (someone
calls the set method)" so even if event1 doesnt occur you will execute
event1.eventWork() because the timeout occurred. The way to fix this
is before you call the eventWork() method check if the event has
occurred via the isSet() method of Event objects. http://docs.python.org/lib/event-objects.html
Cheers
placid wrote:
On Feb 22, 12:08 pm, mark <rkmr...@gmail.comwrote:
>On 21 Feb 2007 16:10:51 -0800, placid <Bul...@gmail.comwrote:
>>On Feb 22, 10:20 am, mark <rkmr...@gmail.comwrote: On 21 Feb 2007 14:47:50 -0800, placid <Bul...@gmail.comwrote: On Feb 22, 3:23 am, mark <rkmr...@gmail.comwrote: >On 20 Feb 2007 21:26:18 -0800, placid <Bul...@gmail.comwrote: >>On Feb 21, 4:21 pm, "placid" <Bul...@gmail.comwrote: >>>On Feb 21, 4:12 pm, mark <rkmr...@gmail.comwrote: >>>>On 20 Feb 2007 20:47:57 -0800, placid <Bul...@gmail.comwrote: >>>>>On Feb 21, 3:08 pm, mark <rkmr...@gmail.comwrote: >>>>>>Right now I have a thread that sleeps for sometime and check if an
[...]
Perhaps in future we can avoid quoting the whole preceding thread except
when strictly necessary?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: andrewpalumbo |
last post by:
I'm trying to write some code which will split up a vector into two
halves and run a method on the objects in the vector using two seperate
threads. I was hoping to see a near linear speedup on an...
|
by: Cider123 |
last post by:
I ran into a situation where my Window Service had to process 100,000+
files, when I first noticed I needed to tweak various routines.
Everything runs fine, but here's what I ran into:
In the...
|
by: Zytan |
last post by:
I have multiple threads writing to WebBrowser (using a function that
checks InvokedRequired, and if so, invokes itself on the WebBrowser
thread) and they are getting deadlocked.
They only...
|
by: Steve |
last post by:
Hi All,
I've been trying to come up with a good way to run a certain process
at a timed interval (say every 5 mins) using the SLEEP command and a
semaphore flag. The basic thread loop was always...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |