@@ -38,14 +38,14 @@ def __init__(self, kind, qsize=16, **kwargs):
3838 callback = callback , userdata = self ._state , ** kwargs )
3939 self ._state .samplerate = self .samplerate
4040
41- self ._actions = set ()
41+ self ._actions = {}
4242 self ._temp_action_ptr = _ffi .new ('struct action**' )
4343
4444 @property
4545 def actions (self ):
4646 """The set of active "actions"."""
4747 self ._drain_result_q ()
48- return self ._actions
48+ return self ._actions . keys ()
4949
5050 @property
5151 def stats (self ):
@@ -115,19 +115,20 @@ def _check_channels(self, channels, kind):
115115 raise ValueError ('Channel numbers start with 1' )
116116 return channels , mapping
117117
118- def _enqueue (self , action ):
118+ def _enqueue (self , action , keep_alive = None ):
119119 self ._drain_result_q ()
120120 self ._temp_action_ptr [0 ] = action
121121 ret = self ._action_q .write (self ._temp_action_ptr )
122122 if ret != 1 :
123123 raise RuntimeError ('Action queue is full' )
124- self ._actions .add (action )
124+ assert action not in self ._actions
125+ self ._actions [action ] = keep_alive
125126
126127 def _drain_result_q (self ):
127128 """Get actions from the result queue and discard them."""
128129 while self ._result_q .readinto (self ._temp_action_ptr ):
129130 try :
130- self ._actions . remove ( self ._temp_action_ptr [0 ])
131+ del self ._actions [ self ._temp_action_ptr [0 ]]
131132 except KeyError :
132133 assert False
133134
@@ -170,7 +171,7 @@ def play_buffer(self, buffer, channels, start=0, allow_belated=True):
170171 channels = channels ,
171172 mapping = mapping ,
172173 ))
173- self ._enqueue (action )
174+ self ._enqueue (action , keep_alive = buffer )
174175 return action
175176
176177 def play_ringbuffer (self , ringbuffer , channels = None , start = 0 ,
@@ -196,7 +197,7 @@ def play_ringbuffer(self, ringbuffer, channels=None, start=0,
196197 channels = channels ,
197198 mapping = mapping ,
198199 ))
199- self ._enqueue (action )
200+ self ._enqueue (action , keep_alive = ringbuffer )
200201 return action
201202
202203
@@ -235,7 +236,7 @@ def record_buffer(self, buffer, channels, start=0, allow_belated=True):
235236 channels = channels ,
236237 mapping = mapping ,
237238 ))
238- self ._enqueue (action )
239+ self ._enqueue (action , keep_alive = buffer )
239240 return action
240241
241242 def record_ringbuffer (self , ringbuffer , channels = None , start = 0 ,
@@ -261,7 +262,7 @@ def record_ringbuffer(self, ringbuffer, channels=None, start=0,
261262 channels = channels ,
262263 mapping = mapping ,
263264 ))
264- self ._enqueue (action )
265+ self ._enqueue (action , keep_alive = ringbuffer )
265266 return action
266267
267268
0 commit comments