简体   繁体   English

在visual studio代码中同时运行两个python文件

[英]Running two python file at the same time in visual studio code

i have two files, and i want to run both.我有两个文件,我想同时运行。 The first one is basically asking down the prices of stocks and writes them to a database, and the second one using python dash to create a webpage.第一个基本上是询问股票价格并将它们写入数据库,第二个使用 python dash 创建网页。 This webpage is showing the data in real time from the database which is constantly refreshes.该网页实时显示来自不断刷新的数据库的数据。 I tried to use threading but it does not work, because the two files basically function as two infinite while loop.我尝试使用线程但它不起作用,因为这两个文件基本上用作两个无限 while 循环。 How should i solve this problem?我应该如何解决这个问题? The two functions im having problem with are dataMiningScript= fd.financeData(database,1600) and if name == " main ": app.run_server(debug=True)我有问题的两个函数是 dataMiningScript= fd.financeData(database,1600) 和 if name == " main ": app.run_server(debug=True)

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
database=db.dataBase()
homepage=hp.homepage(database)
homepage.timeUpdateCallback(app)
homepage.gaugeRefreshCallback(app)
dataMiningScript= fd.financeData(database,1600)

app.layout = homepage.layoutMaker()



if __name__ == "__main__":
   app.run_server(debug=True)

You can just create two terminals in visual studio code to run both files (see here ).您只需在 Visual Studio 代码中创建两个终端即可运行这两个文件(请参阅此处)。 Or you can create a simple shell script which starts both programs (start a program in the background with a '&' at the end of the command line)或者您可以创建一个简单的 shell 脚本来启动两个程序(在命令行末尾使用“&”在后台启动一个程序)

For some reason i cannot run two python programs at the same time in Visual Studio Code, but i managed to solve this problem with the solution of the first commenter:出于某种原因,我无法在 Visual Studio Code 中同时运行两个 python 程序,但我设法通过第一个评论者的解决方案解决了这个问题:

I opened terminal and search my .py program.我打开终端并搜索我的 .py 程序。 Then i write然后我写

python3 xy.py python3 xy.py

Helpful discussion here: run multiple python scripts at the same time .有用的讨论在这里:同时运行多个 python 脚本

Covers the question posted at the title fairly well.很好地涵盖了标题中发布的问题。

On new window I managed to run the necessary code by typing a command.在新窗口中,我设法通过键入命令来运行必要的代码。 Run Python File button remains tied too original window.运行 Python 文件按钮仍然绑定太原始窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM