Skip to content

Commit

Permalink
Torch Neural Net: Add deconstructor back.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Amos committed Jan 7, 2017
1 parent f9764b9 commit b84b7c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions openface/torch_neural_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/>`_
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand Down

0 comments on commit b84b7c6

Please sign in to comment.