Main Content

terminate

Terminate process associated with Python interpreter

Description

terminate(pe) terminates the process associated with the Python® interpreter if the ExecutionMode property of the Python environment is OutOfProcess. The function throws an error if the property value is InProcess.

MATLAB® automatically removes standalone Python references from the workspace after you call terminate. If you want to use Python again, the best practice is to immediately call pyenv with an updated version value. If a MATLAB variable contains a Python reference, the Python reference becomes a deleted handle after you call terminate. If you launch a new Python process, you can use pyenv to get information about it and terminate to terminate it.

Note

Pressing Ctrl+C does not terminate the out-of-process command.

example

Examples

collapse all

Suppose that you created this MATLABPyHost process.

pyenv
ans = 
  PythonEnvironment with properties:

          Version: "2.7"
       Executable: "C:\Python27\pythonw.exe"
          Library: "C:\windows\system32\python27.dll"
             Home: "C:\Python27"
           Status: Loaded
    ExecutionMode: OutOfProcess
        ProcessID: "8196"
      ProcessName: "MATLABPyHost"

Terminate the process.

terminate(pyenv)

Display information about the current environment.

pyenv
ans = 
  PythonEnvironment with properties:

          Version: "2.7"
       Executable: "C:\Python27\pythonw.exe"
          Library: "C:\windows\system32\python27.dll"
             Home: "C:\Python27"
           Status: Terminated
    ExecutionMode: OutOfProcess

Input Arguments

collapse all

Python environment, specified as a PythonEnvironment object.

Version History

Introduced in R2019b

expand all

See Also