Permalink
Browse files

Torch Neural Net: Add deconstructor back.

1 parent f9764b9 commit b84b7c67f250afcddf018bef2950300d26979db0 @bamos bamos committed Jan 7, 2017
Showing with 10 additions and 2 deletions.
  1. +10 −2 openface/torch_neural_net.py
@@ -48,7 +48,7 @@ class TorchNeuralNet:
net = TorchNeuralNet(model=model)
with net:
- # use Torch' neuronal network
+ # use Torch's neural network
In this way Torch processes will be closed at the end of the `with` block.
`PEP 343 <https://www.python.org/dev/peps/pep-0343/>`_
@@ -89,7 +89,7 @@ def exitHandler():
atexit.register(exitHandler)
def __enter__(self):
- """Part of the context manger' protocol. See PEP 343"""
+ """Part of the context manger protocol. See PEP 343"""
return self
def __exit__(self, exc_type, exc_value, traceback):
@@ -101,6 +101,14 @@ def __exit__(self, exc_type, exc_value, traceback):
if self.p.poll() is None:
self.p.kill()
+
+ def __del__(self):
+ """
+ Kill the Lua subprocess to prevent zombie processes.
+ """
+ if self.p.poll() is None:
+ self.p.kill()
+
def forwardPath(self, imgPath):
"""
Perform a forward network pass of an image on disk.

0 comments on commit b84b7c6

Please sign in to comment.