当前位置: 首页>>代码示例>>Python>>正文


Python ThreadQueue.ThreadQueue类代码示例

本文整理汇总了Python中ThreadQueue.ThreadQueue的典型用法代码示例。如果您正苦于以下问题:Python ThreadQueue类的具体用法?Python ThreadQueue怎么用?Python ThreadQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ThreadQueue类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: YoutubeQueryThread

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)			
开发者ID:4doe,项目名称:enigma2-plugins,代码行数:25,代码来源:MyTubeService.py

示例2: __init__

    def __init__(self, guid=None, **kwargs):
        """Initialise the service. If guid is not provided, one will be
           requested (returned in the callback). Pass callback= or error=
           to receive notification of readiness."""
        ThreadQueue.__init__(self)

        self.guid = guid
        self.add_request(self._setup_client, **kwargs)
开发者ID:danni,项目名称:tramtracker,代码行数:8,代码来源:WebService.py

示例3: __init__

	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()
开发者ID:slo617,项目名称:e2openplugin-SeriesPlugin,代码行数:11,代码来源:SeriesPlugin.py

示例4: doThreadQueue

def doThreadQueue():
    from ThreadQueue import ThreadQueue
    dqc = doQueueClass()
    tq = ThreadQueue(work_function=create_task_url, thread_work_function=dqc.work)
    while True:
        if tq.do_work():
            if dqc.dowork():
                break
            else:
                continue
    print 'end'
开发者ID:fixbugs,项目名称:py-fixbugs-tools,代码行数:11,代码来源:tmptest.py

示例5: testThreadQueue

def testThreadQueue():
    from ThreadQueue import ThreadQueue
    t_dict = {'a': '12', "b": '34'}
    t_dict = ('1', '2')
    tc = testClass(t_dict)
    tq = ThreadQueue(work_function=create_task, thread_work_function=tc.test)
    while True:
        if tq.do_work():
            continue
        else:
            break
    print 'ok'
开发者ID:fixbugs,项目名称:py-fixbugs-tools,代码行数:12,代码来源:main.py

示例6: doThreadQueueNew

def doThreadQueueNew(max_num):
    from ThreadQueue import ThreadQueue
    dqc = doQueueClass()
    tq = ThreadQueue(work_function=create_iter, thread_work_function=dqc.newwork, max_exec_num=max_num)
    while True:
        if tq.do_work():
            if dqc.dowork():
                break
            else:
                continue
        else:
            break
    print 'end'
开发者ID:fixbugs,项目名称:py-fixbugs-tools,代码行数:13,代码来源:tmptest.py

示例7: stop

	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
开发者ID:slo617,项目名称:e2openplugin-SeriesPlugin,代码行数:8,代码来源:SeriesPlugin.py

示例8: __init__

	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)
开发者ID:IPMAN-online,项目名称:enigma2-plugins,代码行数:10,代码来源:MyTubeSearch.py

示例9: __init__

	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.messagepPump_conn = self.messagePump.recv_msg.connect(self.finished)
开发者ID:Haehnchen,项目名称:enigma2-plugins,代码行数:12,代码来源:MyTubeService.py

示例10: SuggestionsQueryThread

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)
开发者ID:IPMAN-online,项目名称:enigma2-plugins,代码行数:24,代码来源:MyTubeSearch.py

示例11: SeriesPluginWorker

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
开发者ID:slo617,项目名称:e2openplugin-SeriesPlugin,代码行数:75,代码来源:SeriesPlugin.py

示例12: SeriesPluginWorker

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)
		
#.........这里部分代码省略.........
开发者ID:Linux-Box,项目名称:enigma2-plugins,代码行数:101,代码来源:SeriesPlugin.py


注:本文中的ThreadQueue.ThreadQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。