后台的无限 While 真正循环 (Python) [英] Infinite While True Loop in the Background (Python)

查看:82
本文介绍了后台的无限 While 真正循环 (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

basically, I have some code like this:

while True:
   number = int(len(oilrigs)) * 49
   number += money
   time.sleep(1)

在此之前,我有一个启动屏幕.然而,由于这个 while true 循环,它会阻止它运行实际的启动屏幕.相反,它只是显示这个.

In front of this I have a start up screen. However because of this while true loop, it blocks it from running the actual start up screen. Instead, it just displays this.

那么如何将代码置于后台?

So how do you put the code in the background?

推荐答案

尝试多线程.

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

这篇关于后台的无限 While 真正循环 (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆