mrkn / pycall.rb

Calling Python functions from the Ruby language
MIT License
1.05k stars 72 forks source link

PyCall hangs after one call with Rails + SciKit Learn #95

Open StephenFiser opened 5 years ago

StephenFiser commented 5 years ago

I'm getting the following error the first time that sklearn is imported:

/Users/stephen/.rvm/rubies/ruby-2.6.2/bin/ruby: No such file or directory -- from multiprocessing.semaphore_tracker import main;main(27) (LoadError)

I'm not a python dev, but it seems semaphore has something to do with parallel processing.

When I'm in a rails console, I can run my code without issues (still get the warning). In the web application, it runs once, then it hangs. If I navigate away from the page where it runs, the app is fine. If I come back to the previous page, it crashes entirely. Would love some help!

mrkn commented 4 years ago

Please show the code and the conditions for reproducing this error.

YaarPatandarAA commented 2 years ago

Having same problem. In my instance I am using a method in an external python module and this is in a Rails controller. After one call is made, I cannot make another call. The second call will hang.


 require 'pycall'
 PyCall.init('python3')
 PyCall.sys.path.append File.dirname("PATH_TO_MODULE")

 def test_python
   mod = PyCall.import_module('MODULE_NAME')
   val = mod.SOME_MODULE_METHOD()

   render json: 
 end
hoblin commented 8 months ago

I have the same problem when I use https://github.com/yohasebe/ruby-spacy (which is based on PyCall). It works when I call Spacy::Language.new("en_core_web_sm") in the rails console. When I call it from the server process (puma) or inside a background job (I tried sidekiq and https://github.com/basecamp/solid_queue) the worker just stuck and the only way i found to unstuck it is to kill the process.

otaviogaiao commented 1 month ago

I'm having the same issue. My Rails app hangs forever when on eager_load = false. The line of code that is doing it is:

PyCall.sys.path.append('./app/lib/python_helpers')

Its on a initializer.

My app is very simple, and it freezes just by having this line.