Skip to content

SocketIO and Gevent - trouble sending two emits asyncronously from one function #1968

Answered by reuip
reuip asked this question in Q&A
Discussion options

You must be logged in to vote

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:

def example_function(value):
     with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
          # Run both tasks
          g1 = executor.submit(task1, value)
          g2 = executor.submit(task2, value)
         
         # Wait, blocks until tasks in list are ready (task 1 always finishes first)
         # Then emit result
         concurrent.futures.w…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@reuip
Comment options

@miguelgrinberg
Comment options

@reuip
Comment options

Answer selected by reuip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants