[Twisted-Python] Traceback from pb-Server
![](https://secure.gravatar.com/avatar/9c24d4fa37b3dc4d77e3fe21238a4573.jpg?s=120&d=mm&r=g)
Hi, Please excuse my bad english, I hope you will understand what I mean, otherwise feel free to ask. I'm trying to get error messages from my server. I'm using twisted 2.0.0 with python 2.4. The server looks like this: from twisted.spread import pb from twisted.internet import reactor, threads class ServerObject(pb.Root): #...some other methods, which aren't involved... def remote_fitness(self, task, taskDescription, serverID): return threads.deferToThread(self.calc, task, serverID, taskDescription) def calc(self, task, serverID, taskDescription): exec('from %s import %s as func' % (taskDescription.fileName,taskDescription.functionName)) #problem: file specified in fileName needn't to be in working directory of server func(task) #calulates something return task if __name__ == '__main__': factory = pb.PBServerFactory(ServerObject()) reactor.listenTCP(8800, factory) reactor.run() The client calls, after connection is made. def1 = root.call_remote("fitness", task, taskDescription, serverID) def1.addCallback(self.serverCB) def1.addErrback(self.serverErrorCB) def serverErrorCB(self, reason): print reason If the pythonscript named taskDescription.fileName isn't there self.serverErrorCB is called - thats ok. But it prints: reason [Failure instance: Traceback from remote host -- Traceback unavailable] But I need to know why the call failed. Can anyone please help me to get the traceback or the exception message that the server prints (exceptions.ImportError: No module named fitfunc2).
![](https://secure.gravatar.com/avatar/2c498e6b589e4a4318a8280da536fb36.jpg?s=120&d=mm&r=g)
Stephan Popp <Stephan.Popp@iisb.fraunhofer.de> writes:
The returned Failure instance should still encapsulate the underlying exception information in the type and value fields, as is usual with Failure objects. One difference from a local Failure instance though is that type will be a string representation of the exception class and not the class object itself in the PB client context. If you stick with failure.trap() and failure.check() for explicit exception checks in errback chains, they handle both the direct class as well as string version, so errback code will work locally or via a PB client. So you can still identify the root exception (ImportError). It just happens to not show up in the default __str__ output for the failure object (e.g., your print in your errback) but if you were to modify that print to explicitly print out the type and value fields, and not just let the failure object generate its own printable format, you can see the information. And checking for an exception itself rather than looking for textual information in a traceback is probably better for production code. If you really want to see the traceback during development/debugging, you should see them output as a log message on the server side (if you have twisted logging going somewhere). Alternatively, I believe you can enable "unsafe" tracebacks (which sends the traceback to remote clients) by setting the unsafeTracebacks attribute in the factory on the side on which the exception is being generated - the PBServerFactory side in your case. For PBServerFactory, it's an optional argument to the constructor. -- David
![](https://secure.gravatar.com/avatar/924729c97a251cf15acf4ce92993a8aa.jpg?s=120&d=mm&r=g)
hi, I have a server that acts as a Flash-XML-Socket Server that pushes data to the clients in a irregular interval. It is running on win2003 server and i get the "too many file descriptors in select()" error when i hit the 512 mark. Is there a way to extend this limit? the poll reactor doesn't seam to work under win. is the win32 reactor better at large simultaneous connections? cheers pat
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Fri, 2005-06-24 at 11:34 +0200, Patrick Lauber wrote:
No, win32eventreactor is worse, it only does 64. The 512 limit comes from Python, it #defines FD_SETSIZE to be 512 in the C socket extension module; the default without this would have been 64 as well. Your options: 1. Compile your own version of the _socket.pyd for Windows, patched to have a higher FD_SETSIZE. 2. Try the IOCP reactor, it might work, and certainly shouldn't have limits on number of sockets. more aggressive timeouts on client connections should help somewhat as well, though they don't solve the real issue.
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Thu, 23 Jun 2005 10:53:31 +0200, Stephan Popp <stephan.popp@iisb.fraunhofer.de> wrote:
Note: exarkun@boson:~$ python Python 2.4.1 (#2, Mar 30 2005, 21:51:10) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def calc(a, b): ... exec 'from %s import %s as func' % (a, b) ... >>> calc("os import system; system('echo Boo'); from foo", "bar") Boo Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 2, in calc File "<string>", line 1, in ? ImportError: No module named foo >>> Jp
![](https://secure.gravatar.com/avatar/830dabd8262f561447e9f83b3710943a.jpg?s=120&d=mm&r=g)
Stephan Popp writes:
Popp> If the pythonscript named taskDescription.fileName isn't there Popp> self.serverErrorCB is called - thats ok. But it prints: Popp> reason [Failure instance: Traceback from remote host -- Traceback unavailable] Popp> But I need to know why the call failed. Can anyone please Popp> help me to get the traceback or the exception message that Popp> the server prints (exceptions.ImportError: No module named Popp> fitfunc2). It's a Failure "instance"... take a look at: http://twistedmatrix.com/documents/current/api/twisted.python.failure.Failur...
![](https://secure.gravatar.com/avatar/2c498e6b589e4a4318a8280da536fb36.jpg?s=120&d=mm&r=g)
Stephan Popp <Stephan.Popp@iisb.fraunhofer.de> writes:
The returned Failure instance should still encapsulate the underlying exception information in the type and value fields, as is usual with Failure objects. One difference from a local Failure instance though is that type will be a string representation of the exception class and not the class object itself in the PB client context. If you stick with failure.trap() and failure.check() for explicit exception checks in errback chains, they handle both the direct class as well as string version, so errback code will work locally or via a PB client. So you can still identify the root exception (ImportError). It just happens to not show up in the default __str__ output for the failure object (e.g., your print in your errback) but if you were to modify that print to explicitly print out the type and value fields, and not just let the failure object generate its own printable format, you can see the information. And checking for an exception itself rather than looking for textual information in a traceback is probably better for production code. If you really want to see the traceback during development/debugging, you should see them output as a log message on the server side (if you have twisted logging going somewhere). Alternatively, I believe you can enable "unsafe" tracebacks (which sends the traceback to remote clients) by setting the unsafeTracebacks attribute in the factory on the side on which the exception is being generated - the PBServerFactory side in your case. For PBServerFactory, it's an optional argument to the constructor. -- David
![](https://secure.gravatar.com/avatar/924729c97a251cf15acf4ce92993a8aa.jpg?s=120&d=mm&r=g)
hi, I have a server that acts as a Flash-XML-Socket Server that pushes data to the clients in a irregular interval. It is running on win2003 server and i get the "too many file descriptors in select()" error when i hit the 512 mark. Is there a way to extend this limit? the poll reactor doesn't seam to work under win. is the win32 reactor better at large simultaneous connections? cheers pat
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Fri, 2005-06-24 at 11:34 +0200, Patrick Lauber wrote:
No, win32eventreactor is worse, it only does 64. The 512 limit comes from Python, it #defines FD_SETSIZE to be 512 in the C socket extension module; the default without this would have been 64 as well. Your options: 1. Compile your own version of the _socket.pyd for Windows, patched to have a higher FD_SETSIZE. 2. Try the IOCP reactor, it might work, and certainly shouldn't have limits on number of sockets. more aggressive timeouts on client connections should help somewhat as well, though they don't solve the real issue.
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Thu, 23 Jun 2005 10:53:31 +0200, Stephan Popp <stephan.popp@iisb.fraunhofer.de> wrote:
Note: exarkun@boson:~$ python Python 2.4.1 (#2, Mar 30 2005, 21:51:10) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def calc(a, b): ... exec 'from %s import %s as func' % (a, b) ... >>> calc("os import system; system('echo Boo'); from foo", "bar") Boo Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 2, in calc File "<string>", line 1, in ? ImportError: No module named foo >>> Jp
![](https://secure.gravatar.com/avatar/830dabd8262f561447e9f83b3710943a.jpg?s=120&d=mm&r=g)
Stephan Popp writes:
Popp> If the pythonscript named taskDescription.fileName isn't there Popp> self.serverErrorCB is called - thats ok. But it prints: Popp> reason [Failure instance: Traceback from remote host -- Traceback unavailable] Popp> But I need to know why the call failed. Can anyone please Popp> help me to get the traceback or the exception message that Popp> the server prints (exceptions.ImportError: No module named Popp> fitfunc2). It's a Failure "instance"... take a look at: http://twistedmatrix.com/documents/current/api/twisted.python.failure.Failur...
participants (6)
-
David Bolen
-
Itamar Shtull-Trauring
-
Jp Calderone
-
Patrick Lauber
-
Peter Lee
-
Stephan Popp