LeartS
LeartS

Reputation: 2896

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. Is there a way I can specify it inside a .tac file instead?

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.

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. 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?

Upvotes: 0

Views: 595

Answers (1)

Glyph
Glyph

Reputation: 31910

A .tac file is intended to be a description of a service that can be run; whereas the options to twistd are options about how to run a service. Therefore it doesn't make sense to put the pidfile filename, or the logging configuration, or anything like that, into a .tac file. 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.

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. 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.

Upvotes: 1

Related Questions