8

I have a Python program that interfaces with the browser, and now I meed to make that as my background process, so that every time I click the button, the program should start running in the background.

Can anyone help me with an easy solution for this?

Sean Hill
  • 14,320
  • 2
  • 45
  • 56
Anusha
  • 925
  • 3
  • 11
  • 13

5 Answers5

6

If you're on a Unix-like system (e.g. Mac OSX, Linux), the command is python myscript &, which runs the command in the background. In general, in bash (as well as most other shells) if you append a & to your command it runs the command in the background.

Rafe Kettler
  • 69,672
  • 18
  • 145
  • 147
  • Thanku for the reply and yes I am using Linux(Ubuntu) as my operating system .I will check the answer and get back to you if any doubts. – Anusha Mar 09 '11 at 04:54
  • 4
    But in this case, if I close my terminal window the python process is killed. – Thiago Chaves Mar 14 '13 at 20:20
2

Depending on the way your script is launched, backgrounding with & may not necessarily work since there's a non-login shell that might be what's launched - and it would terminate when your browser session terminates. But there's a whole existing thread dedicated to this issue: Calling an external command in Python

What you want to do is spawn either a separate process, or perhaps create a daemon that's started by your browser click.

Community
  • 1
  • 1
cybertoast
  • 1,093
  • 10
  • 18
0
nohup python filename.py &
Reza Nazeri
  • 320
  • 3
  • 11
0

And if you're using Windows, this might help: Creating a python win32 service

Community
  • 1
  • 1
jcomeau_ictx
  • 35,098
  • 6
  • 89
  • 99
  • you could also make a batch file with something like: start /b /min myprocess.py, but that's kind of ugly. there are probably other ways to do it too, but I try to steer clear of Windows – jcomeau_ictx Mar 09 '11 at 04:52
0

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" which will fire the script on Linux, is what YOU have to develop.

Hope this helps.

kamal
  • 9,015
  • 28
  • 92
  • 148