Subprocess 语句在 python 控制台中有效,但在服务器密度插件中不起作用?

发布于 2024-08-27 05:35:12 字数 687 浏览 7 评论 0原文

当我将

$ python
>>> import subprocess
>>> r = subprocess.Popen(['/pathto/plugin1.rb'], stdout=subprocess.PIPE, close_fds=True).communicate()[0]
>>> data = eval(r)
>>> data
{'test': 1}

其转换为 服务器密度插件但是每次执行插件时它都会使agent.py守护进程崩溃。我能够将其范围缩小到子流程线,但无法找出原因。异常捕获似乎也不起作用。

这个插件是这样的:

class plugin1:
  def run(self):
    r = subprocess.Popen(['/pathto/plugin1.rb'], stdout=subprocess.PIPE, close_fds=True).communicate()[0]
    data = eval(r)
    return data

我对使用 python 还很陌生,无法真正弄清楚为什么这不起作用。非常感谢您的想法:)

in the python console the following statement works perfectly fine (i guess using eval that way is not really good, but its just for testing purpose in this case and will be replaced with proper parsing)

$ python
>>> import subprocess
>>> r = subprocess.Popen(['/pathto/plugin1.rb'], stdout=subprocess.PIPE, close_fds=True).communicate()[0]
>>> data = eval(r)
>>> data
{'test': 1}

when i convert this into a Serverdensity plugin however it keeps crashing the agent.py daemon everytime it executes the plugin. i was able to narrow it down to the subprocess line but could not find out why. exception catching did not seem to work also.

here how the plugin looks like:

class plugin1:
  def run(self):
    r = subprocess.Popen(['/pathto/plugin1.rb'], stdout=subprocess.PIPE, close_fds=True).communicate()[0]
    data = eval(r)
    return data

I'm quite new to work with python and cant really figure out why this wont work. Thanks a lot for ideas :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偷得浮生 2024-09-03 05:35:12

您在模块中导入了子流程吗?另外,您遇到了什么错误,您可以发布错误消息吗?

Do you have subprocess imported in the module? Also what error are you getting could you post the error message ?

宫墨修音 2024-09-03 05:35:12

切换我的开发盒后(也许是因为 python 版本不同?)我终于能够得到一些正确的错误输出。

那么事情就相当简单了:我真的只需要导入缺少的子流程模块。

对于对该解决方案感兴趣的人:

http://github。 com/maxigs/Server密度-Wrapper-Plugin/blob/master/ruby_plugin.py

尚未完全准备好生产,但已可用于保存输入

After switching my dev box (maybe because of the different python version?) i finally was able to get some proper error output.

Then it was rather simple: I really just needed to import the missing subprocess module.

For who is interested in the solution:

http://github.com/maxigs/Serverdensity-Wrapper-Plugin/blob/master/ruby_plugin.py

Not quite production ready yet, but works already for save input

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文