ValvePython / dota2

🐸 Python package for interacting with Dota 2 Game Coordinator
http://dota2.readthedocs.io
201 stars 32 forks source link

Timed events #23

Closed LadaBr closed 7 years ago

LadaBr commented 7 years ago

Sorry for another question but I really love your py package. I added chat functionality and it works great but I would like to do something like timed event that would repeat every X seconds. I want bot to create lobby for 5 minutes and tell how much time is remaining until lobby is abandoned or all players wont connect.

Example:

@dota.on('channel_join') def channel_joined(msg): print(msg) count = 0 max_time = 20 while True: if count > max_time: break dota.send_message(msg.channel_id,"Time remaining: " + str(max_time)) count = count + 1 time.sleep(1)

But when I use this code it always wait until entire loop is finished. Thanks for help.

LadaBr commented 7 years ago

I already solved it, Now I'm trying to find out whats wrong with something else.

I want to use this package together with django and uwsgi but when i try to load web page when steam client is running I always get this error:

Traceback (most recent call last): File "/usr/local/lib/python3.5/socketserver.py", line 625, in process_request_thread self.finish_request(request, client_address) File "/usr/local/lib/python3.5/socketserver.py", line 354, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/local/lib/python3.5/socketserver.py", line 681, in init self.handle() File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 159, in handle self.raw_requestline = self.rfile.readline(65537) File "/usr/local/lib/python3.5/socket.py", line 575, in readinto return self._sock.recv_into(b) File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/gevent/_socket3.py", line 385, in recv_into self._wait(self._read_event) File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/gevent/_socket3.py", line 157, in _wait self.hub.wait(watcher) File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/gevent/hub.py", line 651, in wait result = waiter.get() File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/gevent/hub.py", line 899, in get return self.hub.switch() File "/var/www/dotaleague.cz/env/lib/python3.5/site-packages/gevent/hub.py", line 630, in switch return RawGreenlet.switch(self) gevent.hub.LoopExit: ('This operation would block forever', <Hub at 0x7f433c1945a0 epoll pending=0 ref=0 fileno=16>)

rossengeorgiev commented 7 years ago

You should spend some time reading how gevent package works. It can probably work with django, but there is some special magic you need to do. Using time.sleep will block your code, unless it's been monkey patched.