简体   繁体   English

如何使 python 文件作为单独的进程/线程运行

[英]How to make a python file run as a seperate process/thread

I am scraping webs using beautifulsoap and Selenium in python.我在python中使用 beautifulsoap 和 Selenium 抓取网页。 in ubuntu when i run a python file like python3 filename.py then i didn't able to perform some other task in the same terminal, until that python script finish its execution.在 ubuntu 中,当我运行 python 文件(如python3 filename.py )时,我无法在同一终端中执行其他任务,直到 python 脚本完成执行。

Is there any way through which i run a python file from terminal and then make it independent from it.有什么方法可以让我从终端运行 python 文件,然后让它独立于它。 so that i can work on the same terminal while that python file is executing in background.这样我就可以在 python 文件在后台执行时在同一个终端上工作。

I will be thankful for your response.我将感谢您的回复。

In order to run script in the background, in macOS and linux you can use:为了在后台运行脚本,在 macOS 和 linux 中,您可以使用:

python3 filename.py &

If you want your script will continue running after the terminal is closed, you can use:如果您希望您的脚本在终端关闭后继续运行,您可以使用:

nohup python3 filename.py &

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

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