[英]Strange error when starting Matlab from Python via Native Messaging Extension (Firefox)
I am trying to run some Matlab Code on an URL that I retrieve from a Firefox Native Messaging app.我正在尝试在从 Firefox Native Messaging 应用程序检索的 URL 上运行一些 Matlab 代码。 I use a python script that uses the Matlab engine to run my scripts.
我使用 python 脚本,该脚本使用 Matlab 引擎来运行我的脚本。 This works perfectly fine:
这工作得很好:
import matlab.engine
import sys
import struct
import time
import subprocess
import logging
# Function to receive Message
def getMessage():
rawLength = sys.stdin.buffer.read(4)
print(rawLength)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
eng = matlab.engine.connect_matlab()
eng.workspace['url'] = message
eng.eval('myMatlabFunc(url)', nargout=0)
getMessage()
Now I want to check if Matlab is running and if not start it:现在我想检查 Matlab 是否正在运行,如果没有启动它:
if not matlab.engine.find_matlab():
subprocess.run('C:\\Program Files\\MatlabR2020b-64bit\\bin\\matlab.exe')
This works and I can run my code afterwards as well:这很有效,之后我也可以运行我的代码:
eng = matlab.engine.connect_matlab()
eng.workspace['var1'] = '1'
But then I encounter a strange behaviour, that I cant explain.但是后来我遇到了一种奇怪的行为,我无法解释。
As soon as the script is finished, Matlab exits without a Warning/Crash/Exception... The weirdest part is, that this only happens if I run the skript via the native messaging connection.脚本完成后,Matlab 将退出而没有警告/崩溃/异常...最奇怪的是,只有当我通过本机消息连接运行脚本时才会发生这种情况。
If I run the script in Pycharm, everythin works as expected.如果我在 Pycharm 中运行脚本,一切都会按预期工作。
I hope someone here can help me figure this out!我希望这里有人可以帮助我解决这个问题!
Thanks, Ben谢谢,本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.