Skip to content

Commit

Permalink
gitter: Maintain a list of threads and create only one thread per room (
Browse files Browse the repository at this point in the history
#20)

Closes #19
  • Loading branch information
meetmangukiya authored and zoni committed Jun 27, 2017
1 parent ca1dc54 commit 9103990
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def __init__(self, config):
'Accept': 'application/json'}
self.bot_identifier = self._get_bot_identifier()

self._joined_rooms_lock = threading.Lock()
self._joined_rooms = []

def _get_bot_identifier(self):
"""
Query the API for the bot's own identifier.
Expand Down Expand Up @@ -307,9 +310,14 @@ def background():
else:
log.debug('Received keep-alive on %s', room.name)

t = threading.Thread(target=background)
t.daemon = True
t.start()
with self._joined_rooms_lock:
if room._uri not in self._joined_rooms:
t = threading.Thread(target=background)
t.daemon = True
t.start()
self._joined_rooms.append(room._uri)
else:
log.info("Already joined %s", room.name)

def rooms(self):
json_rooms = self.readAPIRequest('rooms')
Expand Down

0 comments on commit 9103990

Please sign in to comment.