From d636287ebd99cf4ad044624970869eb97ffafe47 Mon Sep 17 00:00:00 2001 From: yvesf Date: Thu, 28 May 2009 15:36:07 +0000 Subject: buuuh git-svn-id: http://xapek.org/svn/common/omegle@1029 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- omegle.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/omegle.py b/omegle.py index d80075a..9a75a26 100644 --- a/omegle.py +++ b/omegle.py @@ -4,7 +4,7 @@ import urllib import time import json import logging -from threading import Thread, Lock, Condition +from threading import Thread, Lock, Event __all__ = ['OmegleChat', 'get_count'] @@ -22,19 +22,20 @@ class Timer(Thread): self.running = False - self.lock = Condition() + self.event = Event() def run(self): self.running = True - self.lock.acquire() while self.running: + self.logger.debug("Timer.run itertaion") self.func() - self.lock.wait(self.interval) + self.event.wait(self.interval) + self.event.clear() self.logger.debug("self.running == False") def stop(self): self.running = False - self.lock.notify() + self.event.set() class RESTClient(object): headers = { @@ -57,7 +58,7 @@ class RESTClient(object): class OmegleChat(RESTClient): - def __init__(self,poll_interval=0.5): + def __init__(self,poll_interval=0.5,name=""): RESTClient.__init__(self,'www.omegle.com') self.timer = Timer(self.events, poll_interval) @@ -188,7 +189,9 @@ if __name__ == "__main__": logging.basicConfig(level=logging.INFO) print "Lets chat. Type \"quit\" to disconnect" chat = OmegleChat() - chat.on_disconnect = lambda: sys.exit(0) + def exit(self): + sys.exit(0) + chat.on_disconnect = exit chat.start() while 1==1: try: -- cgit v1.2.1