@@ -15,7 +15,6 @@ class BaseManager(object):
15
15
def __init__ (self ):
16
16
self .server = None
17
17
self .rooms = {}
18
- self .pending_removals = []
19
18
self .callbacks = {}
20
19
21
20
def initialize (self , server ):
@@ -27,10 +26,8 @@ def get_namespaces(self):
27
26
28
27
def get_participants (self , namespace , room ):
29
28
"""Return an iterable with the active participants in a room."""
30
- for sid , active in six .iteritems (self .rooms [namespace ][room ]):
31
- if active :
32
- yield sid
33
- self ._clean_rooms ()
29
+ for sid , active in six .iteritems (self .rooms [namespace ][room ].copy ()):
30
+ yield sid
34
31
35
32
def connect (self , sid , namespace ):
36
33
"""Register a client connection to a namespace."""
@@ -56,7 +53,6 @@ def disconnect(self, sid, namespace):
56
53
57
54
def enter_room (self , sid , namespace , room ):
58
55
"""Add a client to a room."""
59
- self ._clean_rooms () # ensure our rooms are up to date first
60
56
if namespace not in self .rooms :
61
57
self .rooms [namespace ] = {}
62
58
if room not in self .rooms [namespace ]:
@@ -66,10 +62,11 @@ def enter_room(self, sid, namespace, room):
66
62
def leave_room (self , sid , namespace , room ):
67
63
"""Remove a client from a room."""
68
64
try :
69
- # do not delete immediately, just mark the client as inactive
70
- # _clean_rooms() will do the clean up when it is safe to do so
71
- self .rooms [namespace ][room ][sid ] = False
72
- self .pending_removals .append ((namespace , room , sid ))
65
+ del self .rooms [namespace ][room ][sid ]
66
+ if len (self .rooms [namespace ][room ]) == 0 :
67
+ del self .rooms [namespace ][room ]
68
+ if len (self .rooms [namespace ]) == 0 :
69
+ del self .rooms [namespace ]
73
70
except KeyError :
74
71
pass
75
72
@@ -126,17 +123,3 @@ def _generate_ack_id(self, sid, namespace, callback):
126
123
id = six .next (self .callbacks [sid ][namespace ][0 ])
127
124
self .callbacks [sid ][namespace ][id ] = callback
128
125
return id
129
-
130
- def _clean_rooms (self ):
131
- """Remove all the inactive room participants."""
132
- for namespace , room , sid in self .pending_removals :
133
- try :
134
- del self .rooms [namespace ][room ][sid ]
135
- except KeyError :
136
- # failures here could mean there were duplicates so we ignore
137
- continue
138
- if len (self .rooms [namespace ][room ]) == 0 :
139
- del self .rooms [namespace ][room ]
140
- if len (self .rooms [namespace ]) == 0 :
141
- del self .rooms [namespace ]
142
- self .pending_removals = []
0 commit comments