python - fork 一个 Python 子进程以在解释器、SSH 死亡、核战争中幸存下来
问题描述
这是两天的斗争,我很困惑。
TLDR:从 Python shell ( >>> "like this"
) 中,启动一个 Python 脚本,quit()
然后me@terminal:~$ exit
.
我努力了:
- 实现的各种守护函数
os.fork()
- 创建/调用带有
Popen
并&
附加的shell脚本 subprocess.Popen(["nohup", "command.py"])
有几种形式
玩具代码- Python 3.6
class MyClass(threading.Thread):
def __init__(self, filepath):
super().__init__()
self.filepath = filepath
def run(self):
import time
i = 0
while True: # Count to 50 in a file forever
if i > 50: i = 0
with open(self.filepath, "a") as afile:
afile.writelines("This is msg {}\n".format(i))
i += 1
time.sleep(1)
如何Thread
在 Python shell 中运行它,以使其在关闭解释器并关闭 SSH 终端时不会死机?
Real Code Django 管理的 PubNub 消息的 DB 消费
见# TODO
线,靠近中心。类实例将PNRunner
在 Django 应用程序的构造中动态启动和终止,因此我不能只在启动时使用 shell 脚本启动它们。
解决方案
推荐阅读
- python-3.x - PyCrypto AES-CTR 模式得到不同的输出
- java - 无法提交事务
- laravel - 模拟对同一类中另一个函数的函数调用
- ios - Swift:尝试更改从另一个 swift 文件调用的函数中对象的属性时意外发现“nil”
- .htaccess - htaccess 410 url 垃圾邮件黑客请求,不包括站点生成的请求
- ionic-framework - Ionic 1:如何定义来自不同选项卡的相同状态的导航
- ios - 使用 APPAUTH swift 自定义 SafariViewController
- angularjs - 如何使用量角器从文本中选择一个句子?
- responsive-design - 使用 Appcelerator Titanium 框架的响应式 UI 设计
- git - git 子模块。分离状态与主人