Main Content

terminate

Terminate process associated with Python interpreter

Description

terminate(pe) terminates the process associated with the Python® interpreter if the ExecutionMode property is OutOfProcess. Throws an error if the property value is InProcess.

MATLAB® automatically removes standalone Python references from the workspace after calling terminate. The best practice is to call pyenv with an updated version value immediately after calling terminate. If you assign a Python reference to a MATLAB data structure, then the Python reference is a deleted handle after calling terminate. If you refer to a deleted handle, then MATLAB launches a new Python process, to acquire information from Python regarding its type. In this case, recall the terminate and pyenv functions.

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

See Also