Continuously running scripts question

G

Guest

Currently, I have some scripts (in particular, applescript
'stay-open' scripts) that run continuously on a Mac through
the day. They look in a certain folder every 30 seconds and
perform the necessary work needed.

I was curious if anyone here on the list does anything similar
with Python? If so, do you use launchd, cron, etc in order to
start up your Python script at the appropriate time(s)? Or do
you just let your Python code run continuously? I'm curious of
the pros and cons with each of these. I'm assuming launchd (or
something similar) is probably the better option since if a
script broke it would start it back up again the next time
around. Launchd also probably doesn't use as much processing
power?

Thanks.

Jay
 
T

Tim Harig

On 2010-06-25 said:
I was curious if anyone here on the list does anything similar
with Python? If so, do you use launchd, cron, etc in order to
start up your Python script at the appropriate time(s)? Or do
you just let your Python code run continuously? I'm curious of

I do both. I use cron for large time intervals so that the script is not
constantly memory resident and I run python continuously, either sleeping
or pausing for a signal, when the time interval is small enough that the
init overhead becomes significant.
the pros and cons with each of these. I'm assuming launchd (or
something similar) is probably the better option since if a
script broke it would start it back up again the next time
around. Launchd also probably doesn't use as much processing
power?

You can do the same thing by implementing a supervisor process that
monitors your worker process so that the supervisor kills and restarts the
worker process if it doesn't appear to be functioning properly or crashes.
Currently, I have some scripts (in particular, applescript
'stay-open' scripts) that run continuously on a Mac through
the day. They look in a certain folder every 30 seconds and
perform the necessary work needed.

It sounds to me, since your script is acting on an event, that it
would benefit from using something like inotify, or whatever your
system equivilant would be (FSEvents for Mac? FAM framework for general
POSIX. There are python modules available.), so that your script can
react when (and only when) it notices changes to the folder in question.
 
T

Tim Harig

It sounds to me, since your script is acting on an event, that it
would benefit from using something like inotify, or whatever your
system equivilant would be (FSEvents for Mac? FAM framework for general
POSIX. There are python modules available.), so that your script can
react when (and only when) it notices changes to the folder in question.

pynotify (Linux inotify):
http://trac.dbzteam.org/pyinotify

FSEvents wrapper:
http://pypi.python.org/pypi/pyobjc-framework-FSEvents/2.2b2

FAM:
C libraries and daemon:
http://savannah.nongnu.org/projects/fam/
Python wrapper:
http://sourceforge.net/projects/python-fam/

Similar functionality is available for other platforms; but, you will need
to look at the documentation for those platforms for information on how to
access it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top