Skip to content
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

@api.background.task example throws error #19

Closed
lavabyrd opened this issue Oct 12, 2018 · 3 comments
Closed

@api.background.task example throws error #19

lavabyrd opened this issue Oct 12, 2018 · 3 comments

Comments

@lavabyrd
Copy link

Currently I'm not able to use the @api.background.task in the example. Stack trace is below, full app file information also available below - Python v 3.6.6

Serving on http://localhost:5000
ERROR:waitress:Exception when serving /
Traceback (most recent call last):
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/waitress/channel.py", line 338, in service
    task.service()
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/waitress/task.py", line 169, in service
    self.execute()
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/waitress/task.py", line 399, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/responder/api.py", line 99, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/responder/api.py", line 93, in wsgi_app
    return DispatcherMiddleware(main, apps)(environ, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/werkzeug/wsgi.py", line 826, in __call__
    return app(environ, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/responder/api.py", line 86, in _wsgi_app
    return self.whitenoise(environ, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/whitenoise/base.py", line 75, in __call__
    return self.application(environ, start_response)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/responder/api.py", line 82, in __wsgi_app
    resp = self._dispatch_request(req)
  File "/Users/mp/.local/share/virtualenvs/resp_test-wtUUHlHQ/lib/python3.6/site-packages/responder/api.py", line 125, in _dispatch_request
    self.routes[route].endpoint(req, resp, **params)
  File "main_app.py", line 14, in hello
    @api.background.task
AttributeError: 'API' object has no attribute 'background'

Full main_app.py file -

import responder
api = responder.API()
@api.route("/")
def hello(req, resp):
    @api.background.task
    def sleep(s=10):
        time.sleep(s)
        print("slept!")
    sleep()
    resp.content = "processing"

if __name__ == '__main__':
    api.run(port=5000)
@lavabyrd
Copy link
Author

It looks like the background attribute isn't being loaded to the API object:

dir(api)
['_API__wsgi_app', '__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', 
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', 
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
'__subclasshook__', '__weakref__', '_dispatch_request', '_resolve_graphql_query', '_session', '_wsgi_app', 
'add_route', 'apps', 'default_response', 'formats', 'graphql_response', 'hsts_enabled', 'mount', 
'path_matches_route', 'redirect', 'route', 'routes', 'run', 'session', 'static_dir', 'status_codes', 'template', 
'template_string', 'templates_dir', 'url_for', 'whitenoise', 'wsgi_app']

@Roach
Copy link

Roach commented Oct 13, 2018

Look like it was just added today but hasn't been released yet: 9b0cae3#diff-554e129ce3806dd33d00eac71a9a086e

@kennethreitz
Copy link
Owner

correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants