【问题标题】:Can I set the twistd pid filename inside the tac configuration file?我可以在 tac 配置文件中设置twistd pid 文件名吗?
【发布时间】:2016-01-21 15:45:08
【问题描述】:

I can set the filename of the .pid file by supplying the --pidfile= option to twistd。有没有办法可以在 .tac 文件中指定它?

上下文:

我的扭曲服务是一个玩游戏并接受多个参数的机器人,例如他的姓名、技能水平等。我正在为每个机器人创建一个.tac 文件(多个机器人可以同时运行),以便每个特定的机器人始终具有相同的参数,我可以使用twisted -y botname.tac 启动它。

我希望 pid 文件的格式为 <bot_nick>.pid,这样不同的机器人就不会使用相同的 pid 文件,而且我可以通过列出 pid 文件来查看两者都在运行。有没有办法我可以在.tac 文件本身中设置它,还是我必须始终在像twistd -y bot1.tac --pidfile=bot1.pid 这样的扭曲命令行选项中手动指定它?

【问题讨论】:

  • 你可能总是写一个 shell 包装器。

标签: python twisted configuration-files pid twistd


【解决方案1】:

.tac 文件旨在描述可以运行的服务;而twistd 的选项是关于如何运行服务的选项。因此,将 pidfile 文件名或日志配置或类似的任何内容放入 .tac 文件是没有意义的。在这种情况下,.pid 文件在您的 .tac 文件被读取时已经被写入,因此即使作为解决方法,也无法做到这一点。

如果你想写一个专门的配置系统,最​​好写一个uses twistd like a library, like this example from the axiomatic tool that ships with the Axiom database的工具。当然,界面可能会更好——目前,你实际上必须使用字符串合成一个文字命令行,并且需要子类化——但这让你可以很好地控制如何你的服务运行,而不会因为 .tac 文件恰好是 Python 而尝试破解其他位的全局状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2015-09-02
    • 2011-04-14
    相关资源
    最近更新 更多