flask-executor icon indicating copy to clipboard operation
flask-executor copied to clipboard

Can't be run outside of scope?

Open dzpt opened this issue 6 years ago • 2 comments

Why you have to bind it to a route? RuntimeError: This decorator can only be used at local scopes when a request context is on the stack. For instance within view functions.

dzpt avatar Sep 09 '19 09:09 dzpt

Same here:

    "This decorator can only be used at local scopes "
RuntimeError: This decorator can only be used at local scopes when a request context is on the stack.  For instance within view functions.

iedmrc avatar Dec 26 '19 11:12 iedmrc

You actually can run outside of a route. Ugly but works

with app.test_request_context():
    executor.submit(...)

t4skforce avatar Jan 13 '20 13:01 t4skforce

Wouldn't call that ugly, I'd call that the standard expectation for every Flask extension. Could add some kind of workaround parameter but there are enough "how do I run Flask-related things outside of a request context?" questions on the internet that I'm not convinced a bespoke solution is warranted.

dchevell avatar Aug 19 '22 10:08 dchevell