后台无限 While True 循环 (Python)

Infinite While True Loop in the Background (Python)

基本上,我有一些这样的代码:

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()