I have written a Python script that checks a certain e-mail address and passes new e-mails to an external program. How can I get this script to execute 24/7, such as turning it into daemon or service in Linux. Would I also need a loop that never ends in the program, or can it be done by just having the code re executed multiple times?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
how about using
$nohup
command on linux?I use it for running my commands on my Bluehost server.
Please advice if I am wrong.
I would recommend this solution. You need to inherit and override method
run
.A simple and supported version is Deamonize Install it from Python Package Index (PyPI):
and then use like:
Use whatever service manager your system offers - for example under Ubuntu use upstart. This will handle all the details for you such as start on boot, restart on crash, etc.
First, read up on mail aliases. A mail alias will do this inside the mail system without you having to fool around with daemons or services or anything of the sort.
You can write a simple script that will be executed by sendmail each time a mail message is sent to a specific mailbox.
See http://www.feep.net/sendmail/tutorial/intro/aliases.html
If you really want to write a needlessly complex server, you can do this.
That's all it takes. Your script simply loops and sleeps.
If you are using terminal(ssh or something) and you want to keep a long-time script working after you log out from the terminal, you can try this:
screen
apt-get install screen
create a virtual terminal inside( namely abc):
screen -dmS abc
now we connect to abc:
screen -r abc
So, now we can run python script:
python Keep_sending_mail.py
from now on, you can directly close your terminal, however, the python script will keep running rather than being shut down
If you want to go back check your script running status, you can use
screen -r abc
again