[Tutor] Running a script in the background (offshoot - sorry, OP)

Ray Jones crawlzone at gmail.com
Mon Sep 3 08:33:30 CEST 2012

On 09/02/2012 06:03 PM, Steven D'Aprano wrote:
> On Sun, Sep 02, 2012 at 03:14:53PM -0700, Ray Jones wrote:
>> This is only tangentially related to the thread. Someone mentioned that
>> so long as a script didn't require user input or output to the user, it
>> could run silently in the background. But is there a way for a Python
>> (2.7.3) script to determine whether it was called by the user or called
>> by something like cron or kalarm? That way user inputs could be used
>> when called by a user, but defaults could be used if run by a bot.
> The usual way to detect this is by checking whether or not there is a 
> terminal available.
> os.isatty(sys.stdout.fileno())
> If the script is running directly in a console, isatty will return True; 
> if it is running from cron, or via a pipe or similar, then it will 
> return False.
Okay. Your solution works with cron - it does not work with kalarm
(KDE's system alarm). The only reason I'm using kalarm rather than cron
to begin with is that kalarm is TZ aware while anacron only looks at the
system TZ (i.e. with kalarm I can start each task based on its own
individual time zone).

I read that fcron is fully TZ aware, but when I tried to install it, it
wanted to automatically remove anacron and the entire kubuntu-desktop!

Now this definitely gets into the Linux side of things. I'll go hit the
Ubuntu forums and see what I can find.

Thanks, everyone.


More information about the Tutor mailing list