-
Hey everyone, I have a function that is triggered by a socket.on event which starts two tasks asyncronously. That part of the code works, I can see that task1 and task2 are started in parallel. However, my goal is to have the first task emit it's result (result1) as soon as it is ready, then the second emit once result2 is in. Currently, my console only shows any change once both task1 and task2 are complete. So it seems like the emit's are blocked or waiting for the function to finish in order to send. I have at the top of my init file the monkey patch, in case that's relevant.
A simplified version of my code looks like this:
On the html side:
I appreciate any thoughts or ideas you've got for me! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I think it depends on what you do in your tasks. If your first task performs blocking or CPU intensive work, then the second task would not have a chance to run and do its thing in parallel. |
Beta Was this translation helpful? Give feedback.
Both of my tasks are API calls, which I didn't think would be blocking. In the end, what worked was switching from gevent to concurrent.futures. Now each emit triggers when it's corresponding task is done, rather than both at the end. Hope it's helpful in case someone else has a similar issue!
So the new code looks like: