简体   繁体   English

我可以在tac配置文件中设置扭曲的pid文件名吗?

[英]Can I set the twistd pid filename inside the tac configuration file?

I can set the filename of the .pid file by supplying the --pidfile= option to twistd . 我可以设置的文件名.pid通过提供文件--pidfile=选项twistd Is there a way I can specify it inside a .tac file instead? 有没有一种方法可以在.tac文件中指定它?

Context: 内容:

My twisted service is a bot that plays a game and accepts multiple parameters like his name, skill level, etc. I am creating a .tac file for each bot (multiple bots can run concurrently) so that each specific bot always has the same parameters and I can launch it with twisted -y botname.tac . 我的服务是一个机器人,它玩游戏并且接受多个参数,例如他的名字,技能水平等。我正在为每个机器人创建一个.tac文件(多个机器人可以同时运行),以便每个特定机器人始终具有相同的参数并且我可以使用twisted -y botname.tac启动它。

I'd like the pid file to be of the form <bot_nick>.pid so that different bots don't use the same pid file and also because I can see which both are running just by listing the pid files. 我希望pid文件的格式为<bot_nick>.pid以便不同的bot不使用相同的pid文件,并且还因为我可以通过列出pid文件来查看两者都在运行。 Is there a way I could set this in the .tac file itself or do I have to always manually specify it in the twistd command line options like twistd -y bot1.tac --pidfile=bot1.pid ? 有没有一种方法可以在.tac文件本身中进行设置,还是我必须始终在twistd -y bot1.tac --pidfile=bot1.pid命令行选项(如twistd -y bot1.tac --pidfile=bot1.pid手动指定它?

A .tac file is intended to be a description of a service that can be run ; .tac文件是对可以运行服务的描述; whereas the options to twistd are options about how to run a service . twistd选项是关于如何运行服务的选项。 Therefore it doesn't make sense to put the pidfile filename, or the logging configuration, or anything like that, into a .tac file. 因此,将pidfile文件名,日志记录配置或类似内容放入.tac文件没有任何.tac In this case, the .pid file has already been written by the time your .tac file is being read, so there is no possible way to do it, even as a workaround. 在这种情况下,在.pid文件时已经写入.tac文件,因此即使解决方法也无法实现。

If you want to write a specialized configuration system, it's better to write a tool that uses twistd like a library, like this example from the axiomatic tool that ships with the Axiom database . 如果您想编写一个专门的配置系统,最​​好编写一个像库一样使用twistd的工具, 例如Axiom数据库随附的axiomatic工具中的示例 The interface could stand to be better of course – currently, you actually have to synthesize a literal command line using strings, as well as requiring subclassing – but this lets you have very fine-gained control over how your service runs, without trying to hack up other bits of global state just because .tac files happen to be Python. 该接口可以站是当然的更好-目前,你确实有使用字符串,以及要求子类合成文字命令行-但是这可以让你有过怎样为您服务的运行速度非常了精细的控制,而不试图破解只是因为.tac文件恰好是Python,所以.tac了其他一些全局状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM