question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support uvicorn + fastapi

See original GitHub issue

Uvicorn runs server in event loop and backoff raises TypeError

Traceback (most recent call last):
  File "/Users/sergey/projects/nuc-gateway/venv/bin/uvicorn", line 11, in <module>
    load_entry_point('uvicorn==0.8.4', 'console_scripts', 'uvicorn')()
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/main.py", line 258, in main
    run(**kwargs)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/main.py", line 279, in run
    server.run()
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/main.py", line 307, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/main.py", line 314, in serve
    config.load()
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/config.py", line 186, in load
    self.loaded_app = import_from_string(self.app)
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/uvicorn/importer.py", line 20, in import_from_string
    module = importlib.import_module(module_str)
  File "/Users/sergey/.pyenv/versions/3.7.3/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./app/api_app.py", line 14, in <module>
    from app.api import api_v1
...
  File "./app/itm/client.py", line 142, in <module>
    class APIClient(requests_client.Client):
  File "./app/itm/client.py", line 450, in APIClient
    @retry401
  File "/Users/sergey/projects/nuc-gateway/venv/lib/python3.7/site-packages/backoff/_decorator.py", line 181, in decorate
    "backoff.on_exception applied to a regular function "
TypeError: backoff.on_exception applied to a regular function inside coroutine, this will lead to event loop hiccups. Use backoff.on_exception on coroutines in asynchronous code.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
smagafurovcommented, Oct 8, 2019

My current ugly workaround:

import backoff
backoff._decorator._is_event_loop = lambda: False
2reactions
bgreen-litlcommented, Dec 1, 2019

Okay! This makes more sense to me. I think it may be fine to remove the check all together then. I will look into doing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run a Server Manually - Uvicorn - FastAPI
The main thing you need to run a FastAPI application in a remote server machine is an ASGI server program like Uvicorn. There...
Read more >
Uvicorn
The uvicorn command line tool is the easiest way to run your application. ... It allows Django to support WebSockets, background tasks, and...
Read more >
How to Create a FastAPI / Uvicorn Server Windows Service
Uvicorn is an ASIG web server implementation for Python [5]. It can be used with FastAPI to create and host your web servers....
Read more >
FastAPI, uvicorn.run() always create 3 instances, but I want ...
Could anyone can help how can I get single running worker? Code: import uvicorn from fastapi import FastAPI from fastapi.templating import ...
Read more >
Best practice to run FastAPI on Cloud Run with server port ...
I commit to help with one of those options ... import uvicorn import os from fastapi import FastAPI, Request from fastapi.staticfiles ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found