Commit 4d045403 authored by Luke Macken's avatar Luke Macken

reverse: Ensure we don't permanently hijack stdout/err or leave sockets open

parent fa2cffe2
...@@ -109,9 +109,10 @@ class ReversePythonConnection(ReverseConnection): ...@@ -109,9 +109,10 @@ class ReversePythonConnection(ReverseConnection):
output = buffer.getvalue() output = buffer.getvalue()
except: except:
output = traceback.format_exc() output = traceback.format_exc()
sys.stdout = sys.__stdout__ finally:
sys.stderr = sys.__stderr__ sys.stdout = sys.__stdout__
buffer.close() sys.stderr = sys.__stderr__
buffer.close()
self.send(output) self.send(output)
return True return True
...@@ -186,6 +187,6 @@ class ReversePythonShell(threading.Thread, pyrasite.PyrasiteIPC): ...@@ -186,6 +187,6 @@ class ReversePythonShell(threading.Thread, pyrasite.PyrasiteIPC):
pass pass
except: except:
traceback.print_exc(file=sys.__stderr__) traceback.print_exc(file=sys.__stderr__)
finally:
sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__ sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
self.close() self.close()
...@@ -73,8 +73,8 @@ def shell(): ...@@ -73,8 +73,8 @@ def shell():
except: except:
print('') print('')
raise raise
finally:
ipc.close() ipc.close()
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment