Answer the question
In order to leave comments, you need to log in
How to asynchronously run a function that blocks control?
Hello
Liba in the example - python-a2s
Task:
- Write a function that asynchronously starts the game server parser.
Problem:
The parser has a timeout that blocks control. That is, the code is not executed until a response from the game server arrives.
Question:
How to run the parser for several servers and not stumble over the timeout of one server?
# Пример парсера одного сервера
def parse_of_server(server_address):
try:
server_info = a2s.info(server_address)
except:
server_info = None
return server_info
Answer the question
In order to leave comments, you need to log in
1) find any asynchronous parser code (asyncio, loop - that's all )
2) replace calls with calls to your function (operation is not guaranteed)
discard
read about multithreading and multiprocessing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question