Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   RE: Windows XP - cron or scheduler for Python? (http://www.velocityreviews.com/forums/t332498-re-windows-xp-cron-or-scheduler-for-python.html)

Tim Golden 06-24-2004 08:42 AM

RE: Windows XP - cron or scheduler for Python?
 
| I'm trying to have some scripts run periodically on Windows
| XP and found the "Task Scheduler" did not execute my scripts.
| My scripts are of the form scriptName.py, and will run just
| by invoking that name in the Command Prompt.
|
| Has anyone used the Windows Task Scheduler to run .py
| scripts, and if so is there some intracacy to it?
|
| Is there a more UNIX version of a cron program one can run on Windows?


Others have already responded on using the Task Scheduler,
and maybe you've already set yourself up that way. There
certainly are cron-like programs on Win32 (and, let's face
it, it's not hard to write your own). But I'm initially
very pleased with Irmen de Jong's Kronos from
http://www.razorvine.net/download/kronos.py.

As a test, I run the following script -- usually with
pythonw.exe to avoid an unncessary console window -- and
it pops up every two minutes with a message box. You can
obviously do anything you like with the tasks, and you
have the choice of interval-based or time-of-day-based
tasks. It wouldn't be at all hard to read the info from
a crontab-style file at startup (don't know if Irmen's
already working on anything like that).

<code>

import kronos
import win32ui

def do_reminder ():
win32ui.MessageBox ("This is a reminder", "Reminder")

s = kronos.Scheduler ()
s.addIntervalTask (
action = do_reminder,
taskname = "Reminder",
initialdelay = 0,
interval = 120,
processmethod = s.PM_SEQUENTIAL,
actionargs = []
)
s.start ()
while 1:
try:
try:
pass
except KeyboardInterrupt:
break
finally:
s.stop ()

</code>


TJG


__________________________________________________ ______________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
__________________________________________________ ______________________


Irmen de Jong 06-24-2004 05:47 PM

Re: Windows XP - cron or scheduler for Python?
 
Tim Golden wrote:

> | I'm trying to have some scripts run periodically on Windows
> | XP and found the "Task Scheduler" did not execute my scripts.
> | My scripts are of the form scriptName.py, and will run just
> | by invoking that name in the Command Prompt.
> |
> | Has anyone used the Windows Task Scheduler to run .py
> | scripts, and if so is there some intracacy to it?
> |
> | Is there a more UNIX version of a cron program one can run on Windows?
>
>
> Others have already responded on using the Task Scheduler,
> and maybe you've already set yourself up that way. There
> certainly are cron-like programs on Win32 (and, let's face
> it, it's not hard to write your own). But I'm initially
> very pleased with Irmen de Jong's Kronos from
> http://www.razorvine.net/download/kronos.py.


Thanks for that :) Kronos could use a bit of extra testing.

Mind you that you will have to have it running to execute
the tasks you schedule. This is rather obvious, but if the
original poster wants to run scripts without having to take
care of this himself, it's a bit of a problem.

> tasks. It wouldn't be at all hard to read the info from
> a crontab-style file at startup (don't know if Irmen's
> already working on anything like that).


I'm not. Kronos is meant to be an "embedded" scheduler.
But, as you say, it would be rather trivial to parse a
config file at startup time, where a bunch of tasks
are defined.

Tip: you can use os.system as the task action.... ;-)

--Irmen

Irmen de Jong 06-24-2004 09:09 PM

Re: Windows XP - cron or scheduler for Python?
 
Tim Golden wrote:

[...]
> s.start ()
> while 1:
> try:
> try:
> pass
> except KeyboardInterrupt:
> break
> finally:
> s.stop ()


That's not a very good way of doing that.
This will eat 100% CPU time, it's a busy wait loop...
You should use time.sleep or something else to avoid
busy waiting.
But since you used the 'regular' Scheduler class from
Kronos, it will loop inside the s.start() by itself ... ;-)

--Irmen

Tim Golden 06-25-2004 09:00 PM

Re: Windows XP - cron or scheduler for Python?
 
Irmen de Jong wrote:
> Tim Golden wrote:
>
> [...]
>
>> s.start ()
>> while 1:
>> try:
>> try:
>> pass
>> except KeyboardInterrupt:
>> break
>> finally:
>> s.stop ()

>
>
> That's not a very good way of doing that.
> This will eat 100% CPU time, it's a busy wait loop...
> You should use time.sleep or something else to avoid
> busy waiting.
> But since you used the 'regular' Scheduler class from
> Kronos, it will loop inside the s.start() by itself ... ;-)
>
> --Irmen


Thanks. For some reason it doesn't actually use
100% CPU, otherwise I'd have spotted it slowing down
my machine. I take the point, though. To be honest,
I was just trying the thing out. Also, I have to
kick myself for even writing that particular piece
of code like that.

TJG

Emilio 12-23-2004 07:15 PM

Re: Windows XP - cron or scheduler for Python?
 
Cron clients for Windows to find they are expensive, or have bugs and
are not stable. So I wrote a very simple yet powerful script that
handles all the basic functionality of Cron. It has been stable and
used in production for about a year. The source code is in Python and
you can read it, it is a simple page. I have also created a version for
Windows with an installer that doesn't even require Python installed in
the target machine.

You can find the project here:
http://sourceforge.net/projects/pycron

Emilio.



All times are GMT. The time now is 05:50 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57