Gobot1234 / steam-ext-csgo

An extension for https://github.com/Gobot1234/steam.py to interact with the CS-GO Game Coordinator.
MIT License
5 stars 2 forks source link

Fix name clash and ConnectionClosed exception in Client.connect method #2

Closed somespecialone closed 2 years ago

somespecialone commented 2 years ago

Hi! I really like your work, so thank you for that! I found, that little annoying moment - my Pycharm code inspection didn't work properly, so i decided to fix it. Also, while i closed the client, connect method always throws ConnectionReset exception. After some inspection i made sure that problem was there:

async def connect(self):
    async def ping():
        await self.wait_until_ready()
        while True:   # <- and there
            await self.ws.send_gc_message(GCMsgProto(Language.ClientHello))   # <- there
            await asyncio.sleep(30)

    await asyncio.gather(
        super().connect(),
        ping(),
    )

Unconditional while loop working and coroutine even after client is closed, expectedly, send message to GC trougth closed connection that throws error. I offer simple solution - check is_closed() in while. By the way, you already do this in connect method of steam.Client:

  while not self.is_closed():  # there :)
      last_connect = time.monotonic()

      try:
          self.ws = await asyncio.wait_for(SteamWebSocket.from_client(self, cm_list=self._cm_list), timeout=60)
      except exceptions:
          await throttle()
          continue

I will be grateful if you accept this PR :)

Gobot1234 commented 2 years ago

Out of interest what does pycharm think about Client? I would have thought it would make it steam.Client | csgo.Client and it doesn't care about unions handling every case.

somespecialone commented 2 years ago

Out of interest what does pycharm think about Client? I would have thought it would make it steam.Client | csgo.Client and it doesn't care about unions handling every case.

Maybe all variable messed this up, i am not sure. PyCharm shows right methods in autocomplete, but don't properly handle iheritance(multiple inheritance too, same problem to other parent classes if Client in there), signature of methods, which methods are overriden, super() call

Gobot1234 commented 2 years ago

Oh I remember that being an issue and just being confused. Thanks for this.