New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RQ Worker returns: ModuleNotFound: No module named 'xxxx' #948
Comments
What does your directory structure look like? In what directory are you starting the worker? What happens if you try something like the "Bypassing Workers" section: http://python-rq.org/docs |
Please check your import paths and make sure that your code can import |
Hi, @selwin and @yosemitebandit I think it is not the perfect solution to this question. I am using it with Django and I have a similar problem, RQ's enqueue function can not able to find imported function and also want some specific reason for this. I also searched a lot for this. There is no discussion on it in documentation also. |
Hello guys, I'm facing the same problem. It is possible to have a sample or blueprint in order to understand why this happens. I'm sure is something about my path but after 3 hours I have no solution to this issue. |
@matabares If you are using the Django framework than you can use
And if you are not using the Django then make sure that you give the path of the relevent setting file to your worker script. |
For me this portion of the docs was useful: https://python-rq.org/docs/workers/#performance-notes In particular, the file in which I was starting my workers via w = Worker(qs)
w.work() did not import the function I was trying to add to the queue, thus the worker did not know that function existed |
I have a related question. If I am running the worker on a different machine than the one which submits the jobs to the queue, should both these code be able to import the job function? What happens if they are able to import the function, but the function is different at both ends? Which one will it run? the one at the worker side or the one at the queing side? |
@idling-mind I believe the environment the worker is running on should contain all of the necessary dependencies for running the code. In the case you describe the function on the worker machine would be run. Typically you should start the workers with the same version of code you expect to be called by the main node. |
Thanks. After reading through the docs once more, I realized that I could as well use the function name as a string which makes things easier for me. |
This issue only happened with 'default' queue. With other 'defined' queue ['low', 'high', etc] the module can be loaded perfectly. But as recommended by @idling-mind , just use string as function name.
Correction: Do not use 'default' queue. Define your own queue, save you a lot of trouble. |
rq 1.13.0 gives "resource" module not found on pytest, due to rq instability rq/rq#948
Hi there,
this is not properly an issue but I help I can find some help over here since I am following a very basic python-rq example described at http://python-rq.org/docs/ and it does not work properly.
I created two python files as follows:
requests_test.py
`import requests
def count_words_at_url(url):
resp = requests.get(url)
return len(resp.text.split())`
rq_test_1.py
`from rq import Queue
from redis import Redis
import time
import requests_test
redis_conn = Redis()
q = Queue('TT', connection=redis_conn) # no args implies the default queue
job = q.enqueue(requests_test.count_words_at_url, 'http://nvie.com')
print(job.result)
time.sleep(2)
print(job.result)
So I executed the rq_test_1.py several times in order to add jobs to the queue. After that I started my worker by typing "rqworker TT" on a terminal console (Linux).
The worker gets the jobs but it can't execute them since it cannot find the requests_test module.
What did I do wrong?
WorkerLog: https://ibb.co/hiCQ7S
The text was updated successfully, but these errors were encountered: