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


Python ThreadQueue.push方法代码示例

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


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

示例1: YoutubeQueryThread

# 需要导入模块: from ThreadQueue import ThreadQueue [as 别名]
# 或者: from ThreadQueue.ThreadQueue import push [as 别名]
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,代码行数:27,代码来源:MyTubeService.py

示例2: SuggestionsQueryThread

# 需要导入模块: from ThreadQueue import ThreadQueue [as 别名]
# 或者: from ThreadQueue.ThreadQueue import push [as 别名]
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,代码行数:26,代码来源:MyTubeSearch.py

示例3: SeriesPluginWorker

# 需要导入模块: from ThreadQueue import ThreadQueue [as 别名]
# 或者: from ThreadQueue.ThreadQueue import push [as 别名]
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,代码行数:77,代码来源:SeriesPlugin.py

示例4: SeriesPluginWorker

# 需要导入模块: from ThreadQueue import ThreadQueue [as 别名]
# 或者: from ThreadQueue.ThreadQueue import push [as 别名]
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,代码行数:103,代码来源:SeriesPlugin.py


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