Program chaining on Windows

Chris Angelico rosuav at gmail.com
Sun Aug 23 19:57:44 EDT 2020


On Mon, Aug 24, 2020 at 9:51 AM Rob Cliffe via Python-list
<python-list at python.org> wrote:
> Let me describe my actual use case.  I am developing a large Python
> program (in Windows, working in DOS boxes) and I constantly want to
> modify it and re-run it.  What I have been doing is to make it respond
> to a hotkey by calling itself via os.system.  The problem is that if I
> do this 50 times I am left with 51 instances still running, each one
> waiting for the next to finish.  That's actually OK, except that when I
> finally shut it down, it takes a long time (about 2.5 sec per instance).
>
> I have found a workaround: a small shell program which calls the main
> program (wth os.system), then when the latter exits, calls it again (if
> required).  Starting the main program is slightly slower, but acceptably
> so; shutting it down becomes constant time.
>
> But I would still like to be able to do it as I originally planned, if
> possible.  Not least because I may have other uses for program
> "chaining" in future.
>

Hmm. Python isn't really set up to make this sort of thing easy. My
recommendations, in order of priority, would be:

1) What you're doing, but with a dedicated exit code that means
"changed, please restart me"

2) The same thing but entirely within Python. Instead of importing
modules, manually load them and exec the source code. (No relation to
the process-level exec - I'm talking about the exec function.)
Updating is way WAY faster, but it isn't the same thing as restarting.
Your code has to be built with this in mind.

3) Similar to #2 but using a language that's designed with that kind
of thing in mind. Off topic for this list but it's something I've done
on a number of occasions, so I'd be happy to discuss that with you.

4) Any other option available

5) Messing with exec on Windows

ChrisA


More information about the Python-list mailing list