Steve Hall
Steve Hall

Reputation: 469

twisted python - tac, or py?

I'm hoping this is going to be the simplest question I ever ask here! I've googled etc, but not found anything definitive. I have a .tac file - which I know is a twisted application. I can run this by executing:

twistd -ny mailserver.tac

if I did the following, would the behaviour be any different (ie, what IS so significant about using the twistd executable, and .tac suffix files?

mv mailserver.tac mailserver.py
python mailserver.py

or even, without the rename:

python mailserver.tac

Any guidance on the differences would be welcomed!

Upvotes: 1

Views: 2677

Answers (1)

Jean-Paul Calderone
Jean-Paul Calderone

Reputation: 48335

The file extension doesn't really matter. All twistd (and even python) does is read the contents and evaluate them. The filename is almost entirely irrelevant.

However, using twistd instead of python to run the file is pretty important. If you run a file that is meant to be a .tac file using python that little or nothing of interest will happen. This should be evident from reading the .tac file. None of the important code that makes anything interesting happen gets executed according to the normal rules of how python evaluates and executes a source file.

Consider emailserver.tac. The only top-level code it includes is a few class definitions and a call to a function that instantiates and returns an Application instance. If you evaluate this with python you'll get an Application instance and then the program will complete and exit. Compare this to what happens if you use twistd - which the same things as python does but then also starts the application and runs the reactor.

Upvotes: 3

Related Questions