Is there a conventional way to run python scripts from a Ruby on Rails webserver?
I have a Ruby on Rails site that is currently deployed to Heroku (I can deploy to AWS or wherever this is possible).
I would like for people to upload, and execute arbitrary python scripts on certain page requests (that we review for security). The python scripts should be relatively short running (few seconds tops), mostly to parse or process data. Ideally we would let users upload a script in any language, but python is the most important for now.
1 Answer 1
There are several ways to do this. The most obvious one would be to write another web service, this one in Python, but that's hardly elegant. Another solution:
Install rubypython gem.
Then you can do things like:
require 'rubypython'
RubyPython.start
my_python_module = RubyPython.import('my.python.module')
value = my_python_module.my_python_function().rubify
RubyPython.stop
You can see more at rubypython documentation pages.
A third option would be to simply shell out and execute Python as any executable, through IO.popen.
3 Comments
bash), like Kernel.system and IO.popen do. RubyPython bridge is definitely cleaner though, I believe. I do not know about the performance; I think RubyPython.start should be slow, and you could probably do that only once in the app initialisation stage.Explore related questions
See similar questions with these tags.