I'm new to Python and I wrote a few command line scripts to do some computations. In Perl I remember using PersistantPerl to speed up Perl scripts by running them persistently.
Think of it as something like FastCGI but for command line scripts. PersistantPerl always keep a copy of the interpreter running then background so there's so startup penalty each time the script is run.
Is there an equivalent tool in Python or are there other strategies to avoid paying the startup penalty for running the same Python script frequently.
PersistenPerl
UPDATE:
Someone seems to have stumbled upon with the same idea:
Reducing the Python startup time
But it looks more like a hack than a complete solution. Any modules out there that can do this?
One thing that may make more of an impact than keeping the Python interpreter running (if that's even possible) is making sure that Python doesn't have to compile your script every time it runs it.
The simplest way to achieve that would be to have a small startup script that import
s your actual script. Imported scripts are saved as precompiled .pyc
files and can thus be re-run faster (as far as startup time is concerned).
If this is really a big issue, you could convert your script to run as a daemon and/or webservice which gets invoked by a command line tool?
See:
https://pypi.python.org/pypi/python-daemon/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With