[英]How to read users input when in loop (and without blocking work in this loop)?
如何在循环中读取用户输入(并且在此循环中没有阻塞工作)?
我想做一些基本的东西,比如切换DEBUG变量,打印某些变量的值等用户将要打印的某些特定键,但是我的程序在常量循环中工作,并且这个循环触发另一个线程。 我怎样才能做到这一点?
使用线程:
import threading
import time
value = 3
def process():
while True:
print(value)
time.sleep(1)
thread = threading.Thread(target=process)
thread.start()
while True:
value = input('Enter value: ')
(由于两个循环打印到终端的东西,输出在这里变得混乱,但我认为这个想法应该是清楚的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.