Closed kpister closed 1 year ago
I think you are blocking event loop with sync sleep
I see what you mean, if we use await asyncio.sleep(5)
instead of time.sleep(5)
then the results seem to have the right ordering.
When time.sleep(5) is called, it will block the entire execution of the script and it will be put on hold, just frozen, doing nothing. But when you call await asyncio.sleep(5), it will ask the event loop to run something else while your await statement finishes its execution.
Okay, so for solving my problem, I'll need to transition the network call to use an async call instead of whatever it is currently doing. This is very helpful, thank you!
I have a task listening on a topic and I send messages to the topic from the web endpoint for the app. The task is flagged with
concurrency=2
but cannot handle multiple records at the same time.Below I have provided an example app (run with
faust -A example_app worker -l INFO -p 5001
) which you can hit a/count/
endpoint to get a counter. For example purposes, I have put atime.sleep(5)
in the task handler, but this could be any slow operation.Workflow:
Hit the count endpoint twice, in quick succession.
`curl -X "POST" "http://localhost:5001/count/"
`curl -X "POST" "http://localhost:5001/count/"
Expected outcome:
Logs should be like
Actual output
Notice the time stamps, despite curling immediately.
Versions
Code