【问题标题】:kill matlab process in task manager using python使用python在任务管理器中杀死matlab进程
【发布时间】:2015-11-07 02:28:23
【问题描述】:

我时不时地遇到这个问题: 我的 python 脚本调用 matlab,运行模拟并关闭 matlab。有时,matlab 无法正常关闭。 然后,我运行构建 Visual Studio dll/lib 的批处理脚本,不幸的是,这些脚本被 matlab 阻止了。

有没有办法使用 python 找到 Matlab 的进程 ID,然后杀死它。
然后我可以将其添加到我的 python 脚本的末尾以安全地关闭 matlab。
谢谢
赛迪

【问题讨论】:

  • 如何从python调用Matlab?我使用 bash 或 ksh,我这样称呼它:matlab_2015a -r "<function with arguments>;exit;"。这从来没有关闭Matlab。您是否在处理仍然可以打开的文件?
  • 好吧,我在 win 7 上使用类似 "C:\Program Files\MATLAB\R2013b\bin\matlab.exe" -nosplash -nodesktop -wait -logfile LogFile.log -minimize -r Mat_func"

标签: python matlab process


【解决方案1】:

要杀死名称中包含“matlab”的所有进程,您可以使用

import os
import psutil

allMatlabIds = [p.pid for p in psutil.process_iter() if "matlab" in str(p.name)]
MatlabIdsToKill = [x for x in allMatlabIds if x != os.getpid()]
for MatlabId in MatlabIdsToKill:
    os.kill(MatlabId, signal.SIGINT)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 2019-02-23
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    相关资源
    最近更新 更多