How to run Python programs in the background?

I have a Python program that interacts with the browser, and now I decided to do it as my background process, so every time I click the button, the program should run in the background.

Can someone help me with a simple solution for this?

+8
python background
source share
5 answers

If you are using a Unix-like system (e.g. Mac OSX, Linux), the python myscript & command will execute the command in the background. In general, in bash (like most other shells), if you add & to your command, it will run the command in the background.

+6
source share

Depending on how your script is launched, focusing and maybe not necessarily working, as there may be a shell running without logging in, and it will stop when your browser session ends. But there is a whole existing thread dedicated to this problem: Calling an external command in Python

What you want to do is create a separate process or create a daemon that is launched by clicking on your browser.

+2
source share

And if you use Windows, this may help: Creating a win32 service for python

0
source share

You can use http://wwwsearch.sourceforge.net/mechanize/faq.html or use http://curl.haxx.se/libcurl/python/ or use:

 * Creating your own HTTP requests using urllib2 standard python library * Using a more advanced library that provides the capability to navigate through a websit simulating a browser such as mechanize. 

but the β€œtrigger” that will run the script on Linux is what you need to develop.

Hope this helps.

0
source share
 nohup python filename.py & 
0
source share

All Articles