File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -30,11 +30,15 @@ def wait(self, timeout: int = 5):
3030 self .events [ident ] = [Event (), time .time ()]
3131
3232 # We have to reimplement event waiting here as we need native thread events to allow gevent context switching
33+ wait_start = time .time ()
3334 while not self .events [ident ][0 ].is_set ():
34- gevent .time .sleep (0 )
35+ now = time .time ()
36+ if now - wait_start > timeout :
37+ return False
38+ gevent .sleep (0 )
3539 return True
3640
37- def set (self ):
41+ def set (self , timeout = 5 ):
3842 """Signal that a new frame is available."""
3943 now = time .time ()
4044 remove = None
@@ -47,9 +51,9 @@ def set(self):
4751 else :
4852 # if the client's event is already set, it means the client
4953 # did not process a previous frame
50- # if the event stays set for more than 5 seconds, then assume
54+ # if the event stays set for more than `timeout` seconds, then assume
5155 # the client is gone and remove it
52- if now - event [1 ] > 5 :
56+ if now - event [1 ] >= timeout :
5357 remove = ident
5458 if remove :
5559 del self .events [remove ]
@@ -60,4 +64,6 @@ def clear(self):
6064 if ident not in self .events :
6165 logging .error (f"Mismatched ident. Current: { ident } , available:" )
6266 logging .error (self .events .keys ())
67+ return False
6368 self .events [id (getcurrent ())][0 ].clear ()
69+ return True
You can’t perform that action at this time.
0 commit comments