News for hackers. Stuff that matters.
Re:Writing Python inside Rust by hypewatch on Friday April 17, 2020 @10:14PM (#22904791)
Why call python from Rust? I think calling rust from python would make more sense. Use it to optimize python functions like how python libraries do with with C (i.e. numpy)
Re:Writing Python inside Rust by FridgeSeal on Friday April 17, 2020 @10:48PM (#22904928)
Suppose I’m building an application in Rust that processes a lot of data, one of the steps in processing that data I maybe want to run through a Python tool like SpaCy or Flair.

How would I go about doing that? I could put the Python code behind a little http API and call it that way, but that’s a bunch of overhead and extra stuff to maintain just to analyse some text. If I embed said Python tools in my Rust code then I can call those tools with significantly less overhead and complexity.

Re:Writing Python inside Rust by kccqzy on Friday April 17, 2020 @10:51PM (#22904945)
Why does it have to have a little http API? Why not just spawn the python tool?
Re:Writing Python inside Rust by FridgeSeal on Friday April 17, 2020 @11:48PM (#22905169)
And communicate with it how?

If you’re suggesting spawning things over shell/cmd line I’m of the opinion that this a generally bad idea.

Re:Writing Python inside Rust by kccqzy on Saturday April 18, 2020 @03:25AM (#22905969)
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?

Re:Writing Python inside Rust by jononor on Saturday April 18, 2020 @03:45AM (#22906033)
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)
Re:Writing Python inside Rust by zetalemur on Saturday April 18, 2020 @06:28AM (#22906723)
> 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).

Re:Writing Python inside Rust by staticassertion on Friday April 17, 2020 @11:16PM (#22905063)
Ok, at that point, why not just write the Python directly in your Rust application?
Re:Writing Python inside Rust by dbsmith83 on Friday April 17, 2020 @11:26PM (#22905097)
Because the code smell reeks? You've greatly increased complexity. Did you read about debugging the whitespace? What a mess.