0

I am currently developing a game using HTTP Requests on it. However, when I do a HTTP Request, the game is freezing until that the request is complete. I heard that some people was telling me to use Threads which I currently tried with AIOHTTP, the code is working but the game is still freezing. Here is the code I tried :

class HTTPRequest:
    """
    Asynchronous HTTP Requests in Python with aiohttp and asyncio
    """
    def __init__(self, url, method="GET", data=None):
        self.url = url
        self.method = method
        self.data = data

    async def request(self):
        async with aiohttp.ClientSession() as session:
            async with session.request(
                self.method, self.url, data=self.data
            ) as response:
                return await response.read()
    
    def get_response(self):
        loop = asyncio.get_event_loop()
        return loop.run_until_complete(self.request())

Can someone help me to know what could be the issue and, if possible provide me some solutions to make Pygame not freezing with HTTP Requests please?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jouca
  • 11
  • 4

0 Answers0