-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Background Tasks stuck other requests when i use a http middleware #4616
Comments
You are blocking event loop by calling Of course there are option to scale it, for example see some fresh reddit discussion, https://www.reddit.com/r/Python/comments/sxovwp/async_io_tasks_vs_threads/ If you are using uvicorn, type in
Having more workers (processes) would give you power to have multiple CPU bound code running in parallel (max is number of processes). Some other - maybe better setups are workers in very different host/processes/containers and some queue. You add job to be done to Redis for example and 'worker' instance collect and execute them one after another. This requires some more complex system so if your requirement is to have MAX of few background task at once, more processes should be enough for you |
it's on me that i forgot to say that i had already use multi workers, even 16 workers(16 cores of my AMD cpu), it still stuck. |
Hi, I might be stuck with some similar situation, what's wrong with my code: @app.middleware("http")
async def signature(request: Request, call_next):
try:
signature = request.headers.get('X-Coding-Signature')
except AttributeError:
return Response(status_code=status.HTTP_403_FORBIDDEN, content='Authentification failed.')
content = await request.body()
sha1 = hmac.new(bytes(SECRET_TOKEN, encoding="utf8"), content, 'sha1')
sha1 = sha1.hexdigest()
calculate_signature = 'sha1=' + sha1
if not calculate_signature == signature:
return Response(status_code=status.HTTP_403_FORBIDDEN, content='Authentification failed.')
else:
return await call_next(request) and the route @app.post('/hook')
def simple_hook(json: dict[str, Any]):
try:
id = json['sender']['id']
name = json['sender']['name']
# eventName = json['eventName']
print("[coding.net] %s(%d): %s. " % (name, id, 'eventName'))
except Error as e:
print("ERROR: %s" % e)
return {'code': -1}
return {'code': 0,'message':'done!'} Everything was just fine without the |
More about your issue: encode/starlette#1441 |
Subscribed, thank you. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
First Check
Commit to Help
Example Code
Description
http middleware
starlette
issue but i could not find a solution yet, anybody tell me how to solve this?Operating System
Windows
Operating System Details
No response
FastAPI Version
0.74.1
Python Version
Python 3.7.10
Additional Context
No response
The text was updated successfully, but these errors were encountered: