Executing a python script while it is running

Lie Ryan lie.1296 at gmail.com
Wed Jun 17 04:49:06 CEST 2009


Zach Hobesh wrote:
>> A lot more information would be useful.  What version of Python, and what
>> operating system environment?  Exactly what would you like to happen when
>> the batch file is invoked a second time?
> 
> I'm running Python 2.6.2 on Windows.  I'm passing filenames to the
> batch files and I need all filenames to be processed.  I can't have
> any fails.  I'm working on logging any fails I do have so that I can
> maybe batch process at the end of the day.
> 
>>  2) let them both run as separate processes
> 
> This sounds like a good option, but I'm not totally sure on how to go
> about this?

For that one, you don't really have to do anything special as long as
both program doesn't try to modify the same file at the same time. If
the two program need to modify the same file, you need to arrange some
coordination, the specifics of which highly depends on what you're
trying to do.

>>  4) queue something to be processed when the first run finishes
> 
> I had the same idea, but I believe it would involve having another
> python script run all day long, which wouldn't necessarily be a bad
> thing, but I'd like to explore other options as well.

You don't necessarily have to have daemon process, cron/scheduled task
can do it as well.


5) detect for another process; if there is, sleep until the it
terminates, then do the job. If there is a good possibility of 3 or more
process, it might be necessary to use a lock file, if the lock file
exists, sleep, else create a lock file and do the job.

>> What provisions does this existing application have for long-running batch
>> files?  Seems the synchronization ought to happen there.  Do you have any
>> constraints on how long your script might take, worst case?  What if the
>> application finishes its tasks at a faster average rate than your script can
>> process them?
> 
> The batch file is moving large video files.  Duration probably ranges
> from 10 sec to 45 mins.  On average, the application takes longer to
> process the files than it does the batch file/python script takes to
> copy them, but I'm concerned about the occasional time that the
> application finishes a small file right after finishing a large file.
> 
> Thanks for your response!
> 
> -Zach



More information about the Python-list mailing list