You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @maxim-xu, if you're following the example I posted above, there's no add() function defined anywhere, only foo(). Other than that I don't think I can help you without looking at your code.
@timorthi Sorry! I'd appreciate it if you could take a look at this.
I just replaced foo() with add. The rest of the code is almost the same, except that at the bottom I have:
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
application.run(port=port, debug=False)
because I was running the flask server locally.
When I run: python app.py & flask rq worker it shows the error I mentioned above.
@maxim-xu Ah ok, this seems to be happening because you're using the Flask.run() command instead of the CLI. In your case the app's __name__ is __main__, which is why the worker process is trying to resolve __main__.foo(). I think you could get around this by naming your file __main__.py, but that's probably not recommended.
I'm not too well-versed with how Flask CLI or RQ handles __name__ with regard to the app instance so I can't comment further, but if you start your app using the Flask CLI FLASK_APP=app.py flask run then it'll solve your problem. Initializing your app instance with something like application = Flask('app') (assuming your file name is app.py) should do the trick too.
Activity
[-]Add getting started section[/-]timorthi commentedon Mar 2, 2018
The current README is a good start, it's just missing a simple example. Maybe adding a section like this would be sufficient?
Example Usage
Define a job and queue it:
Start a worker process:
And you're ready to go!
easyandme commentedon Mar 10, 2018
@timorthi I got
AttributeError: module '__main__' has no attribute 'add'Any thoughts? Many thanks!
timorthi commentedon Mar 10, 2018
Hey @maxim-xu, if you're following the example I posted above, there's no
add()function defined anywhere, onlyfoo(). Other than that I don't think I can help you without looking at your code.easyandme commentedon Mar 10, 2018
@timorthi Sorry! I'd appreciate it if you could take a look at this.
I just replaced
foo()withadd. The rest of the code is almost the same, except that at the bottom I have:because I was running the flask server locally.
When I run:
python app.py & flask rq workerit shows the error I mentioned above.timorthi commentedon Mar 10, 2018
@maxim-xu Ah ok, this seems to be happening because you're using the
Flask.run()command instead of the CLI. In your case the app's__name__is__main__, which is why the worker process is trying to resolve__main__.foo(). I think you could get around this by naming your file__main__.py, but that's probably not recommended.I'm not too well-versed with how Flask CLI or RQ handles
__name__with regard to the app instance so I can't comment further, but if you start your app using the Flask CLIFLASK_APP=app.py flask runthen it'll solve your problem. Initializing your app instance with something likeapplication = Flask('app')(assuming your file name is app.py) should do the trick too.easyandme commentedon Mar 10, 2018
@timorthi Solved. Thank you so much!
blacksteel1288 commentedon Aug 28, 2023
My app runs fine, but when I do a 'flask rq worker' on the CLI to start the worker process I'm getting:
"Error: Detected factory 'create_app' in module 'app', but could not call it without arguments. Use 'app:create_app(args)' to specify arguments."I'm using an application factory pattern with blueprints.
Any thoughts?