Skip to content

Commit 352c3df

Browse files
author
Ask Solem
committed
Cancel the timer2 timer applied by the camera base class.
1 parent a694468 commit 352c3df

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

celery/events/snapshot.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
class Polaroid(object):
9+
_tref = None
910
shutter_signal = Signal(providing_args=("state", ))
1011

1112
def __init__(self, state, freq=1.0, verbose=False):
@@ -14,7 +15,7 @@ def __init__(self, state, freq=1.0, verbose=False):
1415
self.verbose = verbose
1516

1617
def install(self):
17-
timer2.apply_interval(self.freq * 1000.0, self.capture)
18+
self._tref = timer2.apply_interval(self.freq * 1000.0, self.capture)
1819

1920
def on_shutter(self, state):
2021
pass
@@ -29,3 +30,15 @@ def shutter(self):
2930

3031
def capture(self):
3132
return self.state.freeze_while(self.shutter)
33+
34+
def cancel(self):
35+
if self._tref:
36+
self._tref()
37+
self._tref.cancel()
38+
39+
def __enter__(self):
40+
self.install()
41+
return self
42+
43+
def __exit__(self, *exc_info):
44+
self.cancel()

0 commit comments

Comments
 (0)