1

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!

Steve Hall
  • 469
  • 1
  • 5
  • 23
  • 1
    dupliacte - http://stackoverflow.com/questions/1897939/how-do-you-you-run-a-twisted-application-via-python-instead-of-via-twisted – WeaselFox Nov 04 '14 at 14:35
  • What is in `mailserver.py`? – Glyph Nov 05 '14 at 03:05
  • Basically I was trying to work on mailserver.tac (http://twistedmatrix.com/documents/current/_downloads/emailserver.tac) in a windows env, using eclipse and pyDev - but that (unsurprisingly) doesnt recognise tac files. All good though thanks to @WeaselFox pointing out the one thing I'd failed to find by googling ;) If anyone thinks there is value in me pasting my "new" mailserver.py code as an answer by way of a demonstration of how a script can be python / twistd friendly, happy to do so! – Steve Hall Nov 06 '14 at 09:22

1 Answers1

3

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.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122