Lets say the python
repl takes a long time to start up, is there a way to start it up in the background so I can create an alias and feed it commands like python-current "command to run"
.
|
|||
|
There is nothing in the python distribution of doing this kind of opening, 'batteries included' not withstanding. That programs like editors can handle that kind of thing, is because it is quite clear what to do when you open another file: you just open a window/tab on the new file, handled by the same executable. Implementing something like that yourself is not that difficult, but you have to think about what happens when the first command has not finished yet and the second is scheduled:
I have notified running pythons to load and execute modules based on files in a directory that were scanned, http request (on a twisted based system) and with zeromq. What is appropriate depends IMHO what else is needed by the system, I always go with that which works and does have the least overhead. Your Often this was combined with reloading certain modules (to get the processing for new commands). For that you can use the
As an aside: especially when using UI code I have found this reloading useful. Python loading of the executable is comparable with Perl (0.002s on my several years old system, time python -v ). Loading the base modules takes about ten times longer (time python -c "exit();", 0.025s). But when using UI based programs the whole startup easily grows to several seconds and more. And in that case implementing dynamic command reading and having a python-current` makes sense.
|
||||
|
If you use Google for "ksh coprocess example" or "bash coprocess example" and you will find example code. Work from the examples, as the whole thing isn't super intuitive. |
|||
|