]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/raspi_23/pulseio/PulseIn.py
proper deiniting
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / raspi_23 / pulseio / PulseIn.py
index ef77b74344802db707b68aba49f5fd10f6b0a6c1..2cda6471619939483ef83b9d26229b3f923bb7f0 100644 (file)
@@ -47,8 +47,8 @@ class PulseIn:
         if DEBUG:
             print(cmd)
         
-        self.process = subprocess.Popen(cmd)
-        procs.append(self.process)
+        self._process = subprocess.Popen(cmd)
+        procs.append(self._process)
 
         # wait for it to start up
         if DEBUG:
@@ -58,18 +58,18 @@ class PulseIn:
             raise RuntimeError("Could not establish message queue with subprocess")
 
 
-    def __deinit__(self):
-        print("deinit")
-        
-    # TODO: this doesnt work?
+    def deinit(self):
+        # Clean up after ourselves
+        self._process.terminate()
+        procs.remove(self._process)
+        self._mq.remove()
+        queues.remove(self._mq)
+
     def __enter__(self):
-        print("enter")
-        pass # no-op
+        return self
 
-    # TODO: this doesnt work?
     def __exit__(self, exc_type, exc_value, tb):
-        print("exit")
-        #self.process.kill()
+        self.deinit()
 
     def resume(self, trigger_duration=0):
         if trigger_duration != 0: