pushyrpc / pushy

Easy-as RPC. Zero-server RPC for Python and Java.
http://github.com/pushyrpc/pushy
45 stars 18 forks source link

exception writes to stdout #40

Closed bradharmon closed 11 years ago

bradharmon commented 11 years ago

It seems that maybe some debug code has been left in pushy. I'm coming across a situation where I want to try and use a specific python binary, and catch the exception if it doesn't exist.

conn = None
try:
   conn = pushy.connect("local:", python='python2.7')
except:
   conn = pushy.connect("local:")

If the first pushy connection fails, stderr gets plastered with output because of client.py:395-401

Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/pushy/client.py", line 383, in __init__
    self.modules = AutoImporter(self)
  File ".../lib/python2.7/site-packages/pushy/client.py", line 236, in __init__
    remote_compile = self.__client.eval("compile")
  File ".../lib/python2.7/site-packages/pushy/client.py", line 478, in eval
    return self.remote.eval(code, globals, locals)
  File ".../lib/python2.7/site-packages/pushy/protocol/connection.py", line 54, in eval
    return self.send_request(MessageType.evaluate, args)
  File ".../lib/python2.7/site-packages/pushy/protocol/baseconnection.py", line 315, in send_request
    m = self.__waitForResponse(handler)
  File ".../lib/python2.7/site-packages/pushy/protocol/baseconnection.py", line 420, in __waitForResponse
    m = self.__recv()
  File ".../lib/python2.7/site-packages/pushy/protocol/baseconnection.py", line 601, in __recv
    m = self.__istream.receive_message()
  File ".../lib/python2.7/site-packages/pushy/protocol/baseconnection.py", line 104, in receive_message
    return Message.unpack(self.__file)
  File ".../lib/python2.7/site-packages/pushy/protocol/message.py", line 96, in unpack
    header = read(file, Message.PACKING_SIZE)
  File ".../lib/python2.7/site-packages/pushy/protocol/message.py", line 60, in read
    raise IOError, "End of file"
IOError: End of file

[remote] bash: python2.7: command not found

client.py:395-401

import traceback
traceback.print_exc()
errorlines = self.server.stderr.readlines()
print >> sys.stderr, ""
for line in errorlines:
   print >> sys.stderr, "[remote]", line.rstrip()
print >> sys.stderr, ""

I do like that I can tell the reason for the exception due to displaying the output from the remote command as seen above (versus just re-raising an exception that is non-obvious), but I also think I should be able to catch the exception without spamming stderr.

axw commented 11 years ago

Fair call. I suppose the stderr should be consumed and combined with the exception, and presented by the exception's __str__. I likely won't have any time in the near future to fix this, so if you feel up to it please send a pull request. Otherwise I'll fix it later.

axw commented 11 years ago

I lied - found a few minutes, fixed now.