while True:
number = int(len(oilrigs)) * 49
number += money
time.sleep(1)
在此之前,我有一个启动屏幕。然而,由于这是真正的循环,它阻止它运行实际的启动屏幕。相反,它只是显示这个。
那么如何将代码放在后台呢?
答案 0 :(得分:6)
尝试多线程。
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()