Discord-S.C.U.M
Discord-S.C.U.M copied to clipboard
Using multiple bot.gateway.command at the same time causes gateway to drop
I need to run some functions in parallel, so I decided to use threads, the code is the end is a concept, which causes gateway ws connection to drop. I did some debugging and that is what I found out: the reason is another thread tries to call self.ws.run_forever again, and therefore the code tries to open the ws twice. I tried to add some checks like
self._zlib = zlib.decompressobj()
if not reopen_socket and self.ws.sock is not None:
continue
self.ws.run_forever(
ping_interval=10,
ping_timeout=5,
http_proxy_host=self.proxy_host,
http_proxy_port=self.proxy_port,
http_proxy_auth=self.proxy_auth,
proxy_type=self.proxy_type,
**self.connectionKwargs
)
in gateway.py to check if the ws connection is already up, but for some reason, zlib decoder fails to decode the data in that case.
The question is, how should I use the gateway if I need to fetch some info from it while already fetching another data from another @bot.gateway.command processer?
import threading
import time
import discum
bot = discum.Client(email='email', password='password')
def t1():
@bot.gateway.command
def t(_):
print('t1 last error:')
print(bot.gateway._last_err)
time.sleep(5)
bot.gateway.run()
def t2():
@bot.gateway.command
def t(_):
print('t2 last error:')
print(bot.gateway._last_err)
bot.gateway.run()
def main():
threading.Thread(target=t1).start()
threading.Thread(target=t2).start()
if __name__ == '__main__':
main()
Console logs are:
...
t1 last error:
None
t2 last error:
None
**REAL GATEWAY DATA (HIDDEN)**
t1 last error:
None
t2 last error:
None
t1 last error:
None
t2 last error:
None
**REAL GATEWAY DATA (HIDDEN)**
t1 last error:
None
t2 last error:
None
**REAL GATEWAY DATA (HIDDEN)**
t1 last error:
None
t2 last error:
None
t1 last error:
None
t2 last error:
None
[gateway] Connection Dropped. Retrying in 10 seconds.
Same problem, any solution?
It was a long time ago, but as I remember I did all the @bot.gateway.command-functions before calling threaded code