我有以下代码试图启动Linux中的下面的每个"命令".如果出于任何原因要么崩溃,模块会尝试保持两个命令中的每个命令都运行.
#!/usr/bin/env python
import subprocess
commands = [ ["screen -dmS RealmD top"], ["screen -DmS RealmD top -d 5"] ]
programs = [ subprocess.Popen(c) for c in commands ]
while True:
for i in range(len(programs)):
if programs[i].returncode is None:
continue # still running
else:
# restart this one
programs[i]= subprocess.Popen(commands[i])
time.sleep(1.0)
Run Code Online (Sandbox Code Playgroud)
执行代码时,抛出以下异常:
Traceback (most recent call last):
File "./marp.py", line 82, in <module>
programs = [ subprocess.Popen(c) for c in commands ]
File "/usr/lib/python2.6/subprocess.py", line 595, in __init__
errread, errwrite)
File …Run Code Online (Sandbox Code Playgroud) 我有一个必须传递给方法的密码字符串.一切正常,但我不清楚以明文形式存储密码.有没有办法混淆字符串或真正加密它?我知道混淆可以反向设计,但我认为我至少应该尝试掩盖密码.至少它不会被索引程序看到,或者是一个快速查看我的代码的流眼.
我知道pyobfuscate但我不希望整个程序混淆,只是一个字符串,可能是定义变量的整行本身.
目标平台是GNU Linux Generic(如果这有所不同)
我需要检测程序何时崩溃或没有使用python运行并重新启动它.我需要一个不一定依赖python模块作为父进程的方法.
我正在考虑实现一个基本上做的while循环
ps -ef | grep process name
Run Code Online (Sandbox Code Playgroud)
当找不到该过程时,它会启动另一个过程.也许这不是最有效的方法.我是python的新手,所以可能有一个python模块已经这样做了.
我有2个服务器程序,必须使用GNU Screen启动.我想用基于Python的程序来强化这些服务器以防止崩溃,该程序启动每个屏幕会话然后监视服务器进程.如果服务器进程崩溃,我需要python代码来终止无关的屏幕会话并再次使用屏幕重启服务器.
我对python很新,但我正借此机会自学.我知道这可以在bash脚本中完成.但是我想在未来的功能上构建这个代码,所以它需要只是python.
伪代码如下:
thread-one {
While 1:
start server 1 using screen
wait for server to end
end while
}
thread-two {
While 1:
start server 2 using screen
wait for server to end
end while
}
Run Code Online (Sandbox Code Playgroud) 我需要运行以下命令:
screen -dmS RealmD top
Run Code Online (Sandbox Code Playgroud)
基本上在后台调用GNU屏幕,会话标题为"RealmD",顶部命令在屏幕内运行.必须以这种方式调用该命令,因此在重新设置服务器之前,此时不能替换屏幕.(另一个项目另一次)
我已经在top命令中找到了需要运行的服务器二进制文件.但是top是一个不错的替代品,而代码正在为这个python模块进行调试.
我真正需要的是一种在Python中使用上述参数执行屏幕的方法.
python ×5
linux ×3
restart ×2
bash ×1
encryption ×1
gnu-screen ×1
obfuscation ×1
passwords ×1
pid ×1
subprocess ×1