diff options
Diffstat (limited to 'omegle.py')
-rw-r--r-- | omegle.py | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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: |