所以我试着用Python创建一个任务管理器网站,它有一个管理控制台和一个前端网站.最初,一切都工作正常,直到我添加了Flask网页代码(如WebManager_Main. py所示),然后控制台打印(如CommandLine_Input所示)停止工作.奇怪的是,这些线程运行在两个不同的线程(如main.py所示),所以我不知道这是怎么发生的!

Main.py

# Startup and import
# import libraries
import threading
import time
# import files
import CommandLine_Handler as clh
import DataBaseHandler_Main as DBHM
import WebManager_main as WBM
import Error_Handler as eh
import Mailbox as mb

# Startup
mb.run_Main = True
mb.run_Interface = True
mb.run_Database = True
mb.run_WebApp = True
mb.loop_Counter = 0

cmdInterface = None
dataBaseCreate = None
WebAppManager = None

# Run Loop
while mb.run_Main == True:
  if mb.run_Interface == True:
    try:
      if cmdInterface == None:
        cmdInterface = threading.Thread(target = clh.interface)
        cmdInterface.daemon = True
        cmdInterface.start()
      else:
        if not cmdInterface.is_alive():
          cmdInterface = threading.Thread(target = clh.interface)
          cmdInterface.daemon = True
          cmdInterface.start()
    except:
      eh.error("m-rl1")
      
  if mb.run_Database == True:
    try:
      if dataBaseCreate == None:
        dataBaseCreate = threading.Thread(target = DBHM.creator)
        dataBaseCreate.daemon = True
        dataBaseCreate.start()
      else:
        if not dataBaseCreate.is_alive():
          dataBaseCreate = threading.Thread(target = DBHM.creator)
          dataBaseCreate.daemon = True
          dataBaseCreate.start()
    except:
      eh.error("m-rl2")

  if mb.run_WebApp == True:
    try:
      if WebAppManager == None:
        WebAppManager = threading.Thread(target = DBHM.creator)
        WebAppManager.daemon = True
        WebAppManager.start()
      else:
        if not WebAppManager.is_alive():
          WebAppManager = threading.Thread(target = WBM)
          WebAppManager.daemon = True
          WebAppManager.start()
    except:
      eh.error("m-rl3")

        
  mb.loop_Counter += 1
  time.sleep(0.5)

CommandLine_Input. py

import os
import sys
import pwinput as pIN
import logging
def output(input):
  print(input, flush=True)
  # logger = logging.getLogger('werkzeug')
  # logger.info(input)

def uInput(prompt):
   userInput = input(prompt)
   return userInput
def passInput(prompt):
  #userInput = pIN.pwinput(prompt=prompt, mask = '*')
  userInput = input(prompt)
  return userInput

def clear():
  os.system("cls" if os.name == "nt" else "clear")
  #os.system("cls")

WebManager_Main.py

from flask import Flask, render_template
#this is the library responsible for the hosting of the Web app
webApp = Flask(__name__)

@webApp.route("/")

def index():
  return render_template("index.html")

if __name__ == "WebManager_main":
  webApp.run(port=8080, debug = True)

我在网上看了一下人们的帖子,他们有类似的问题和建议.我试过刷新缓冲区,记录以及试图禁用Flask中的打印. 但我似乎再也找不到那个线上的控制台 fingerprint 了.

我将非常感谢任何帮助!

推荐答案

Python Web应用程序必须由实现WSGI协议的软件独立运行.

查看Flask documentation以了解如何启动您的Web应用程序. 你不能像在代码中那样把它作为线程运行.

Python相关问答推荐

使用LineConnection动画1D数据

将DF中的名称与另一DF拆分并匹配并返回匹配的公司

acme错误-Veritas错误:模块收件箱没有属性linear_util'

当使用keras.utils.Image_dataset_from_directory仅加载测试数据集时,结果不同

从numpy数组和参数创建收件箱

为什么sys.exit()不能与subproccess.run()或subprocess.call()一起使用

如何根据一列的值有条件地 Select 前N组?

如何在TensorFlow中分类多个类

在pandas数据框中计算相对体积比指标,并添加指标值作为新列

幂集,其中每个元素可以是正或负""""

python—telegraph—bot send_voice发送空文件

从列表中获取n个元素,其中list [i][0]== value''

交替字符串位置的正则表达式

循环浏览每个客户记录,以获取他们来自的第一个/最后一个渠道

如何在Python 3.9.6和MacOS Sonoma 14.3.1下安装Pyregion

如何过滤组s最大和最小行使用`transform`'

GPT python SDK引入了大量开销/错误超时

Python将一个列值分割成多个列,并保持其余列相同

如何将返回引用的函数与pybind11绑定?

将参数从另一个python脚本中传递给main(argv