user1261487
user1261487

Reputation: 1

stack dump in twisted app.py 'application' error when using twistd but works with python?

I am trying to use twisted but when i try to run some of the example code provided with the twisted package, it seems to always crash when i use "twistd" instead of "python"

for example, using the example code given with twisted, if i run to command : twisted -ny echoserv.py

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/twisted/application/app.py", line 652, in run
    runApp(config)
  File "/usr/lib/python2.7/site-packages/twisted/scripts/twistd.py", line 23, in runApp
    _SomeApplicationRunner(config).run()
  File "/usr/lib/python2.7/site-packages/twisted/application/app.py", line 386, in run
    self.application = self.createOrGetApplication()
  File "/usr/lib/python2.7/site-packages/twisted/application/app.py", line 451, in createOrGetApplication
    application = getApplication(self.config, passphrase)
---  ---
  File "/usr/lib/python2.7/site-packages/twisted/application/app.py", line 462, in getApplication
    application = service.loadApplication(filename, style, passphrase)
  File "/usr/lib/python2.7/site-packages/twisted/application/service.py", line 405, in loadApplication
    application = sob.loadValueFromFile(filename, 'application', passphrase)
  File "/usr/lib/python2.7/site-packages/twisted/persisted/sob.py", line 211, in loadValueFromFile
    value = d[variable]
exceptions.KeyError: 'application'

Failed to load application: 'application'
Could not find 'application' in the file. To use 'twistd -y', your .tac
file must create a suitable object (e.g., by calling service.Application())
and store it in a variable named 'application'. twistd loads your .tac file
and scans the global variables for one of this name.

Please read the 'Using Application' HOWTO for details.


I was using Twisted version 11.0.0 but then i tried 12.0.0 but i have the same problem.

The version of python i am using is 2.7.2

Any ideas on what to do would be helpful. I have been trying to deal with this problem for a few days now. thanks!

Upvotes: 0

Views: 570

Answers (2)

Jean-Paul Calderone
Jean-Paul Calderone

Reputation: 48335

To use 'twistd -y', your .tac file must create a suitable object (e.g., by calling service.Application()) and store it in a variable named 'application'. twistd loads your .tac file and scans the global variables for one of this name.

Please read the 'Using Application' HOWTO for details.

Upvotes: 0

Thomas Orozco
Thomas Orozco

Reputation: 55197

twistd -y is meant to be used with a python file that contains a variable called application, there is none in this file, so it's not going to work.

You might want to spend some time reading twistd's documentation so you get a clearer idea of its role in the twisted ecosystem.

Upvotes: 1

Related Questions