织物跑叉
我想使用 Fabric.api.run 直接启动远程框中的应用程序。由于应用程序需要很长时间才能完成,因此我希望能够分叉一个子进程,这样我就不需要等待很长时间。
代码如下:
from fabric.api import run
....
run("python ./myApp.py --fork=True >myApp.log 2>&1")
我使用以下代码来启用分叉端代码:
if settings.fork:
child_pid = os.fork()
if child_pid == 0:
print "Starting Child Process: PID# %s" % os.getpid()
else:
print "Terminating Parent Process: PID# %s" % os.getpid()
os._exit(0)
问题是在我执行运行命令后,我进入远程框,发现程序已因某种未知原因退出,我检查了日志文件,里面什么都没有。
有人可以让我知道如何解决这个问题吗?非常感谢!
I want to use Fabric.api.run to directly start an application in a remote box. Since the application takes really a long to finish, I wish to be able to fork a child process, such that I don't need to wait for a long time.
The code is like:
from fabric.api import run
....
run("python ./myApp.py --fork=True >myApp.log 2>&1")
I used the following code to enable forking side the code:
if settings.fork:
child_pid = os.fork()
if child_pid == 0:
print "Starting Child Process: PID# %s" % os.getpid()
else:
print "Terminating Parent Process: PID# %s" % os.getpid()
os._exit(0)
The problem is after I do the run command, I sshed into the remote box, and found out the program has been quit for some unknown reason, I check the log file, there is nothing there.
Somebody could let me know how I can work this around? Many thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
说到分叉,除了许多其他改进之外,Fabric 有一个分叉可以实现并行执行。
http://tav.espians.com /fabric-python-with-cleaner-api-and-parallel-deployment-support.html
根据您正在做的事情,您可能需要考虑这一点。
除此之外,我认为您想使用
multiprocessing
:http:// docs.python.org/library/multiprocessing.html
Talking of forks, there is a fork of Fabric that enables parallel execution, apart from lots of other improvements.
http://tav.espians.com/fabric-python-with-cleaner-api-and-parallel-deployment-support.html
Depending on what you are doing, you may want to consider that.
Apart from that, I think you want to use
multiprocessing
:http://docs.python.org/library/multiprocessing.html