基本上,我有一些这样的代码:
while True:
number = int(len(oilrigs)) * 49
number += money
time.sleep(1)
在此之前我有一个启动屏幕。然而,由于这个 while true 循环,它会阻止它运行实际的启动屏幕。相反,它只是显示这个。
那么如何将代码放在后台呢?
尝试多线程。
import threading
def background():
while True:
number = int(len(oilrigs)) * 49
number += money
time.sleep(1)
def foreground():
# What you want to run in the foreground
b = threading.Thread(name='background', target=background)
f = threading.Thread(name='foreground', target=foreground)
b.start()
f.start()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)