[英]How do I run a function alongside my main code?
def explain():
Timer = 60
keyboard.press("/")
time.sleep(0.1)
keyboard.write(StillInBeta)
time.sleep(0.8)
keyboard.press('enter')
time.sleep(0.8)
keyboard.press("/")
time.sleep(0.1)
keyboard.write(Reminder)
time.sleep(0.8)
keyboard.press('enter')
time.sleep(0.1)
for x in range(60):
Timer = Timer - 1
time.sleep(1)
print(Timer)
Explain_And_Remind = threading.Thread(target=explain())
Explain_And_Remind.join()
I've tried .start(), .run(), and .join().我试过 .start()、.run() 和 .join()。 Searching gave me nothing.搜索给了我什么。 I'm not sure how to go about doing this.我不知道该怎么做。 I'm running all code in a while true statement.我在 while true 语句中运行所有代码。
This is a very common mistake, even experienced people also miss these paranthesis.这是一个很常见的错误,即使是有经验的人也会错过这些括号。
The target argument of the thread takes a function object.线程的目标参数采用函数对象。 For example -例如 -
def greet():
print('Hello!')
Here greet
is a function object, whereas greet()
calls the function.这里greet
是一个函数对象,而greet()
调用函数。
In your case, you are calling the function, which is not intended.在您的情况下,您正在调用该函数,这不是故意的。
You have to pass the function object, threading.Thread(target=explain)
您必须传递函数对象threading.Thread(target=explain)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.