Just fork and exec. Or if you fancy, posix_spawn a separate process. Then communicate over pipes, or if you have a lot of outputs from these tools, collect results from the file system.
Really, where does this fear of spawning things come from?
Python module loading tends to be quite slow.
Loading Tensorflow on our Heroku production environment takes 10 seconds (5 on my laptop). A client of mine running Rust and Python on Embedded Linux device found that loading numpy/pandas modules took over 5 seconds (laptop was under 1), and their computation took just x00 milliseconds. 10x overhead...
So the spawning of a short-lived subprocess approach has massive overhead, only suitable for multi-second workloads.
Re:Writing Python inside Rust
by sfkdjf9j3j on Saturday April 18, 2020 @01:22AM
(#22905510)
What's wrong with forking and using a pipe or socket?
Re:Writing Python inside Rust
by umanwizard on Saturday April 18, 2020 @06:17AM
(#22906670)
Spawning an external binary does not necessarily involve the shell (if it did, how could the shell itself spawn things? It’d be shells all the way down)
> And communicate with it how?
The simplest approach is via a pipe to the process' stdin/stdout I guess. Of course you have to (de)serialize your data, but you would have to to the same if you go the HTTP route, which seems far more complex. Furthermore the suggested solution probably has a nice wrapper in the language's stdlib (e.g. `check_output()` in Python land).
If you’re suggesting spawning things over shell/cmd line I’m of the opinion that this a generally bad idea.