class YoutubeQueryThread(Thread): def __init__(self, query, param, gotFeed, gotFeedError, callback, errorback): Thread.__init__(self) self.messagePump = ePythonMessagePump() self.messages = ThreadQueue() self.gotFeed = gotFeed self.gotFeedError = gotFeedError self.callback = callback self.errorback = errorback self.query = query self.param = param self.canceled = False self.messagePump.recv_msg.get().append(self.finished) def cancel(self): self.canceled = True def run(self): try: feed = self.query(self.param) self.messages.push((True, feed, self.callback)) self.messagePump.send(0) except Exception, ex: self.messages.push((False, ex, self.errorback)) self.messagePump.send(0)
class SuggestionsQueryThread(Thread): def __init__(self, query, param, callback, errorback): Thread.__init__(self) self.messagePump = ePythonMessagePump() self.messages = ThreadQueue() self.query = query self.param = param self.callback = callback self.errorback = errorback self.canceled = False self.messagePump.recv_msg.get().append(self.finished) def cancel(self): self.canceled = True def run(self): if self.param not in (None, ""): try: suggestions = self.query.getSuggestions(self.param) self.messages.push((suggestions, self.callback)) self.messagePump.send(0) except Exception as ex: self.messages.push((ex, self.errorback)) self.messagePump.send(0) def finished(self, val): if not self.canceled: message = self.messages.pop() message[1](message[0])
class SuggestionsQueryThread(Thread): def __init__(self, query, param, callback, errorback): Thread.__init__(self) self.messagePump = ePythonMessagePump() self.messages = ThreadQueue() self.query = query self.param = param self.callback = callback self.errorback = errorback self.canceled = False self.messagePump.recv_msg.get().append(self.finished) def cancel(self): self.canceled = True def run(self): if self.param not in (None, ""): try: suggestions = self.query.getSuggestions(self.param) self.messages.push((suggestions, self.callback)) self.messagePump.send(0) except Exception, ex: self.messages.push((ex, self.errorback)) self.messagePump.send(0)
class SeriesPluginWorker(Thread): def __init__(self, callback): Thread.__init__(self) self.callback = callback self.__running = False self.__messages = ThreadQueue() self.__pump = ePythonMessagePump() try: self.__pump_recv_msg_conn = self.__pump.recv_msg.connect(self.gotThreadMsg) except: self.__pump.recv_msg.get().append(self.gotThreadMsg) self.__queue = ThreadQueue() def empty(self): return self.__queue.empty() def finished(self): return not self.__running def add(self, item): self.__queue.push(item) if not self.__running: self.__running = True self.start() # Start blocking code in Thread def gotThreadMsg(self, msg=None): data = self.__messages.pop() if callable(self.callback): self.callback(data) def stop(self): self.running = False self.__queue = ThreadQueue() try: self.__pump.recv_msg.get().remove(self.gotThreadMsg) except: pass self.__pump_recv_msg_conn = None def run(self): while not self.__queue.empty(): # NOTE: we have to check this here and not using the while to prevent the parser to be started on shutdown if not self.__running: break logDebug('Worker is processing') item = self.__queue.pop() result = None try: result = item.identifier.getEpisode( item.name, item.begin, item.end, item.service ) except Exception, e: logDebug("Worker: Exception:", str(e)) # Exception finish job with error result = str(e) config.plugins.seriesplugin.lookup_counter.value += 1 self.__messages.push( (item.callback, normalizeResult(result)) ) self.__pump.send(0) logDebug(' Worker: list is emty, done') Thread.__init__(self) self.__running = False
class SeriesPluginWorker(Thread): def __init__(self, callback): Thread.__init__(self) self.callback = callback self.__running = False self.__messages = ThreadQueue() self.__pump = ePythonMessagePump() try: self.__pump_recv_msg_conn = self.__pump.recv_msg.connect(self.gotThreadMsg) except: self.__pump.recv_msg.get().append(self.gotThreadMsg) self.__queue = ThreadQueue() def empty(self): return self.__queue.empty() def finished(self): return not self.__running def add(self, item): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker add from thread: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) self.__queue.push(item) if not self.__running: self.__running = True self.start() # Start blocking code in Thread def gotThreadMsg(self, msg=None): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker got message: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) data = self.__messages.pop() if callable(self.callback): self.callback(data) def stop(self): self.running = False try: self.__pump.recv_msg.get().remove(self.gotThreadMsg) except: pass self.__pump_recv_msg_conn = None def run(self): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker got message: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) while not self.__queue.empty(): # NOTE: we have to check this here and not using the while to prevent the parser to be started on shutdown if not self.__running: break item = self.__queue.pop() splog('SP: Worker is processing') result = None try: result = item.identifier.getEpisode( item.name, item.begin, item.end, item.service ) except Exception, e: splog("SP: Worker: Exception:", str(e)) # Exception finish job with error result = str(e) config.plugins.seriesplugin.lookup_counter.value += 1 splog("SP: Worker: result") if result and len(result) == 4: season, episode, title, series = result season = int(CompiledRegexpNonDecimal.sub('', season)) episode = int(CompiledRegexpNonDecimal.sub('', episode)) title = title.strip() splog("SP: Worker: result callback") self.__messages.push( (item.callback, (season, episode, title, series)) ) else: splog("SP: Worker: result failed") self.__messages.push( (item.callback, result) ) self.__pump.send(0) #from twisted.internet import reactor #reactor.callFromThread(self.gotThreadMsg) splog('SP: Worker: list is emty, done') Thread.__init__(self) self.__running = False
class SeriesPluginWorker(Thread): def __init__(self, callback): Thread.__init__(self) self.callback = callback self.__running = False self.__messages = ThreadQueue() self.__pump = ePythonMessagePump() try: self.__pump_recv_msg_conn = self.__pump.recv_msg.connect(self.gotThreadMsg) except: self.__pump.recv_msg.get().append(self.gotThreadMsg) self.__queue = ThreadQueue() def empty(self): return self.__queue.empty() def finished(self): return not self.__running def add(self, item): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker add from thread: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) self.__queue.push(item) if not self.__running: self.__running = True self.start() # Start blocking code in Thread def gotThreadMsg(self, msg=None): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker got message: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) data = self.__messages.pop() if callable(self.callback): self.callback(data) def stop(self): self.running = False try: self.__pump.recv_msg.get().remove(self.gotThreadMsg) except: pass self.__pump_recv_msg_conn = None def run(self): from ctypes import CDLL SYS_gettid = 4222 libc = CDLL("libc.so.6") tid = libc.syscall(SYS_gettid) splog('SP: Worker got message: ', currentThread(), _get_ident(), self.ident, os.getpid(), tid ) while not self.__queue.empty(): # NOTE: we have to check this here and not using the while to prevent the parser to be started on shutdown if not self.__running: break item = self.__queue.pop() splog('SP: Worker is processing') result = None try: result = item.identifier.getEpisode( item.name, item.begin, item.end, item.service ) except Exception, e: splog("SP: Worker: Exception:", str(e)) # Exception finish job with error result = str(e) config.plugins.seriesplugin.lookup_counter.value += 1 if result and len(result) == 4: splog("SP: Worker: result callback") season, episode, title, series = result season = int(CompiledRegexpNonDecimal.sub('', season)) episode = int(CompiledRegexpNonDecimal.sub('', episode)) title = title.strip() if config.plugins.seriesplugin.replace_chars.value: repl = re.compile('['+config.plugins.seriesplugin.replace_chars.value.replace("\\", "\\\\\\\\")+']') splog("SP: refactor title", title) title = repl.sub('', title) splog("SP: refactor title", title) splog("SP: refactor series", series) series = repl.sub('', series) splog("SP: refactor series", series) self.__messages.push( (item.callback, (season, episode, title, series)) ) else: splog("SP: Worker: result failed") self.__messages.push( (item.callback, result) ) self.__pump.send(0) #from twisted.internet import reactor #reactor.callFromThread(self.gotThreadMsg) splog('SP: Worker: list is emty, done') Thread.__init__(self) self.__running = False