这类似于here。你知道吗
我正尝试在输入过程中对我正在使用套接字的聊天系统执行其他操作,但链接中的方法在python 3中似乎不起作用,下面的代码稍加修改:
import thread
import time
waiting = 'waiting'
i = 0
awesomespecialinput = None
def getinput():
global var
awesomespecialinput = input("what are you thinking about")
thread.start_new_thread(getinput,())
while awesomespecialinput == None:
waiting += '.'
print(waiting)
i += 1
time.sleep(1)
print('it took you',i,'seconds to answer')
和输出:
Traceback (most recent call last):
File "/home/pi/python/inputtest2.py", line 1, in <module>
import thread
ImportError: No module named 'thread'
我不知道线程,但想有一些有用的前瞻性线程,如果有的话。你知道吗
编辑
更改代码:
import threading
import time
waiting = 'waiting'
i = 0
awesomespecialinput = None
def getinput():
global awesomespecialinput
awesomespecialinput = input("what are you thinking about")
threading.start_new_thread(getinput,())
while awesomespecialinput == None:
waiting += '.'
print(waiting)
i += 1
time.sleep(1)
print('it took you',i,'seconds to answer')
输出:
AttributeError: module 'threading' has no attribute 'start_new_thread'
在python3中,可以将^{} 与
getinput
函数一起用作target
参数:(您尝试使用的} API的高级包装器。)
start_new_thread
方法在python3的threading
模块中不可用,因为它是^{相关问题 更多 >
编程相关推荐