arokem / python-matlab-bridge

A simple Python => MATLAB(R) interface and a matlab_magic for ipython
BSD 2-Clause "Simplified" License
332 stars 97 forks source link

How to exit gracefully Matlab on exception (SIGINT) #235

Open fbrundu opened 8 years ago

fbrundu commented 8 years ago

I am writing a script that run Matlab from pymatbridge. When I stop the script with SIGINT (Ctrl-C), the Matlab instance fails to close. How can I close it? This is my code:

class Schedule(object):
    exposed = True

    def __init__(self):
        # FIXME
        self.mlab_path = "/Applications/MATLAB_R2015a.app/bin/matlab"
        self.mlab = Matlab(executable=self.mlab_path)
        self.mlab.start()

    def __enter__(self):
        pass

    def __exit__(self, exc_type, exc_value, traceback):
        self.mlab.stop()