[Twisted-Python] run python application with twistd -y ifinger.tac, error occurs. please help to check
Experts: 您好! my ifinger.tac file content like following: fromtwisted.applicationimportinternet, servicefromtwisted.internetimportprotocol, reactor, deferfromtwisted.protocolsimportbasicclassFingerProtocol(basic.LineReceiver): deflineReceived(self, user): d = self.factory.getUser(user) defonError(err): return'Internal error in server'd.addErrback(onError) defwriteResponse(message): self.transport.write(message + '\r\n') self.transport.loseConnection() d.addCallback(writeResponse) classFingerFactory(protocol.ServerFactory): protocol = FingerProtocoldef__init__(self, **kwargs): self.users = kwargsdefgetUser(self, user): returndefer.succeed(self.users.get(user, "No such user")) application = service.Application('finger', uid=1, gid=1) factory = FingerFactory(moshez='Happy and well') internet.TCPServer(79, factory).setServiceParent(service.IServiceCollection(application)) when running this script with command-line : twistd -y ifinger.tac, error occurs like : Traceback (most recent call last): File "/usr/local/bin/twistd", line 7, in <module> import _preamble ImportError: No module named '_preamble' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/twistd", line 9, in <module> sys.exc_clear() AttributeError: 'module' object has no attribute 'exc_clear' And i run python3 in interactive mode to check if exc_clear method is defined in sys, command line like :
import sys sys.__dict__["exc_clear"] Traceback (most recent call last): File "<stdin>", line 1, in <module> sys.exc_clear() KeyError: 'exc_clear'
Is there any configuration i should do ? please help to give me an answer. 谢谢!! ---------------------------- 姓名 : 吴志高/Charles 电话 : (+086)13410859946 邮箱 : wuzhigaoem@163.com ================================================
Hi Charles, Yes, twistd doesn't appear to work on py3k. Not being able to import _preamble is normal (once Twisted has been installed), but _preamble does assume sys.exc_clear exists, which isn't true on 3.x. I couldn't find any ticket on this. Perhaps you should file it (and maybe fix it!) :) It's my understanding that the new except clause semantics are expected to take care of this problem. Can someone comment as to why this was put there in the first place, and, specifically, why it can't just be "pass"? Is there some logging system that looks at the current exception or something when twistd (or some other script) starts? cheers lvh
On 09:06 am, _@lvh.io wrote:
Hi Charles,
Yes, twistd doesn't appear to work on py3k. Not being able to import _preamble is normal (once Twisted has been installed), but _preamble does assume sys.exc_clear exists, which isn't true on 3.x.
I couldn't find any ticket on this. Perhaps you should file it (and maybe fix it!) :)
I think there are still many unported dependencies of `twistd` to port first.
It's my understanding that the new except clause semantics are expected to take care of this problem.
Can someone comment as to why this was put there in the first place, and, specifically, why it can't just be "pass"? Is there some logging system that looks at the current exception or something when twistd (or some other script) starts?
Both `log.err()´ and `Failure()´ look at the current exception. If we don't `sys.clear_exc()´ here then the first piece of code that tries to use either of those may get a surprising result. The current exception state can last a long time so this surprise can hide for a remarkably long time before showing up. The exception state also holds references to lots of extra things on the stack which is undesirable even if there are no other side-effects. Jean-Paul
On Tue, Sep 17, 2013 at 2:14 PM,
I think there are still many unported dependencies of `twistd` to port first.
Sure, but every little bit helps, right? :)
Can someone comment as to why this was put there in the first place, and,
specifically, why it can't just be "pass"? Is there some logging system that looks at the current exception or something when twistd (or some other script) starts?
Both `log.err()´ and `Failure()´ look at the current exception. If we don't `sys.clear_exc()´ here then the first piece of code that tries to use either of those may get a surprising result. The current exception state can last a long time so this surprise can hide for a remarkably long time before showing up.
Okay, cool. From what I understand: 1. _preamble is just a hack to get bin/whatever to work right without installing (i.e. from a checkout) 2. (not too sure about this) in py3k, except statements do the clearing bit already: www.python.org/dev/peps/pep-3110/#semantic-changes So, does that mean we can do a try: ... ; except AttributeError and be done with it? The exception state also holds references to lots of extra things on the
stack which is undesirable even if there are no other side-effects.
Jean-Paul
lvh
On 04:10 pm, _@lvh.io wrote:
On Tue, Sep 17, 2013 at 2:14 PM,
wrote: I think there are still many unported dependencies of `twistd` to port first.
Sure, but every little bit helps, right? :)
It doesn't make a lot of sense to me to port things that depend on unported things. The little bit that would help would be porting one of the unported dependencies.
Can someone comment as to why this was put there in the first place, and,
specifically, why it can't just be "pass"? Is there some logging system that looks at the current exception or something when twistd (or some other script) starts?
Both `log.err()´ and `Failure()´ look at the current exception. If we don't `sys.clear_exc()´ here then the first piece of code that tries to use either of those may get a surprising result. The current exception state can last a long time so this surprise can hide for a remarkably long time before showing up.
Okay, cool. From what I understand:
1. _preamble is just a hack to get bin/whatever to work right without installing (i.e. from a checkout) 2. (not too sure about this) in py3k, except statements do the clearing bit already: www.python.org/dev/peps/pep-3110/#semantic-changes
So, does that mean we can do a try: ... ; except AttributeError and be done with it?
Sounds like probably yea. The way to know would be to make the change and run the test suite (perhaps first double checking to get an idea of how well covered this is). Revision history suggests the change was made to get a test to pass but it doesn't mention which one. This is why porting the dependencies first makes sense though - you won't be able to run the tests as long as the dependencies are unported. Jean-Paul
Jean-Paul 您好! Thanks for your help. Because i am a fresh man to twisted. I will roll back to version 2.x and try the application again. 谢谢!! ---------------------------- 姓名 : 吴志高/Charles 电话 : (+086)13410859946 邮箱 : wuzhigaoem@163.com ================================================ At 2013-09-17 20:14:08,exarkun@twistedmatrix.com wrote:
On 09:06 am, _@lvh.io wrote:
Hi Charles,
Yes, twistd doesn't appear to work on py3k. Not being able to import _preamble is normal (once Twisted has been installed), but _preamble does assume sys.exc_clear exists, which isn't true on 3.x.
I couldn't find any ticket on this. Perhaps you should file it (and maybe fix it!) :)
I think there are still many unported dependencies of `twistd` to port first.
It's my understanding that the new except clause semantics are expected to take care of this problem.
Can someone comment as to why this was put there in the first place, and, specifically, why it can't just be "pass"? Is there some logging system that looks at the current exception or something when twistd (or some other script) starts?
Both `log.err()´ and `Failure()´ look at the current exception. If we don't `sys.clear_exc()´ here then the first piece of code that tries to use either of those may get a surprising result. The current exception state can last a long time so this surprise can hide for a remarkably long time before showing up.
The exception state also holds references to lots of extra things on the stack which is undesirable even if there are no other side-effects.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
exarkun@twistedmatrix.com
-
Laurens Van Houtven
-
吴志高