Skip to content

Run two API requests asynchronously, but display results one at a time #1957

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

You must be logged in to vote

You are using a test request context, which only makes sense in unit tests. Probably not what's causing your problem, but that needs to be removed.

def get_moderator_response(user_response):
    with gevent.Timeout(15):
        # code that checks the moderator API. Assume no offensive language
        socketio.emit('moderator_result',{'result': user_response}, namespace='/')  # <-- add namespace here, since it cannot be obtained from the request context

You also need to make sure you don't block when you connect to these 3rd party APIs.

Besides that I'm not sure what else to suggest.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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