[Pkg-privacy-commits] [pyptlib] 17/136: Fixed subprocess buffering issues

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository pyptlib.

commit d0561f73302150d0160b1a2262174770e1fba6b0
Author: Brandon Wiley <brandon at blanu.net>
Date:   Fri Jun 15 12:52:24 2012 -0500

    Fixed subprocess buffering issues
---
 src/pyptlib/framework/client.py      | 20 +++++++++++++++++---
 src/pyptlib/framework/server.py      | 11 +----------
 src/pyptlib/manager/manager.py       |  8 +++++---
 src/pyptlib/manager/serverManager.py |  3 +--
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/pyptlib/framework/client.py b/src/pyptlib/framework/client.py
index 77c3b7f..14f814b 100755
--- a/src/pyptlib/framework/client.py
+++ b/src/pyptlib/framework/client.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python -u
 
+import os
 import sys
-import time
 
 from struct import unpack
 from socket import inet_ntoa
@@ -16,22 +16,31 @@ from pyptlib.framework.loopback import FakeSocket
 
 from pyptlib.framework.socks import SocksHandler
 
+from pyptlib.config.config import EnvException
 from pyptlib.config.client import ClientConfig
 from pyptlib.framework.daemon import *
 
+from pyptlib.transports.dummy import DummyClient
+
 class ManagedClient(Daemon):
   def __init__(self):
     try:
       Daemon.__init__(self, ClientConfig(), SocksHandler())
+    except EnvException:
+      print('error 0')
+      return
     except UnsupportedManagedTransportVersionException:
+      print('error 1')
       return
     except NoSupportedTransportsException:
+      print('error 2')
       return
 
     try:
-      self.launchClient(self.supportedTransport)
-      self.config.writeMethod(self.supportedTransport)
+      self.launchClient(self.supportedTransport, 8182)
+      self.config.writeMethod(self.supportedTransport, 5, ('127.0.0.1', 8182), None, None)
     except TransportLaunchException as e:
+      print('error 3')
       self.config.writeMethodError(self.supportedTransport, e.message)
 
     self.config.writeMethodEnd()
@@ -45,3 +54,8 @@ class ManagedClient(Daemon):
     client=DummyClient()
     self.handler.setTransport(client)
     add_service(Service(self.handler, port=port))    
+
+if __name__=='__main__':
+  sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+  server=ManagedClient()
+  
\ No newline at end of file
diff --git a/src/pyptlib/framework/server.py b/src/pyptlib/framework/server.py
index c93a16d..08b2e09 100755
--- a/src/pyptlib/framework/server.py
+++ b/src/pyptlib/framework/server.py
@@ -2,7 +2,6 @@
 
 import os
 import sys
-import time
 
 from struct import unpack
 from socket import inet_ntoa
@@ -27,7 +26,6 @@ from pyptlib.transports.dummy import DummyServer
 class ManagedServer(Daemon):
   def __init__(self):
     try:
-      print('init')
       Daemon.__init__(self, ServerConfig(), ProxyHandler())
     except EnvException:
       print('error 0')
@@ -40,7 +38,6 @@ class ManagedServer(Daemon):
       return
 
     try:
-      print('launch')
       self.launchServer(self.supportedTransport, 8182)
       self.config.writeMethod(self.supportedTransport, ('127.0.0.1', 8182), MethodOptions())
     except TransportLaunchException as e:
@@ -49,7 +46,6 @@ class ManagedServer(Daemon):
 
     self.config.writeMethodEnd()
     
-    print('run')
     self.run()
     
   def launchServer(self, name, port):
@@ -62,10 +58,5 @@ class ManagedServer(Daemon):
 
 if __name__=='__main__':
   sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
-  print('main')
-  sys.stdout.flush()
-  import time
-  while True:
-    time.sleep(1000)
-#  server=ManagedServer()
+  server=ManagedServer()
   
\ No newline at end of file
diff --git a/src/pyptlib/manager/manager.py b/src/pyptlib/manager/manager.py
index 948b568..b5f0ee9 100644
--- a/src/pyptlib/manager/manager.py
+++ b/src/pyptlib/manager/manager.py
@@ -8,8 +8,10 @@ class Manager:
     os.environ['TOR_PT_MANAGED_TRANSPORT_VER']='1'
 
   def launch(self, path):
-    p=subprocess.Popen(path, stdout=subprocess.PIPE)
-    for b in p.stdout:
-      print('b: '+str(b))
+    p=subprocess.Popen(['python', '-u', path], stdout=subprocess.PIPE)
+    line=p.stdout.readline().strip()
+    while line!=None and line !='':
+      print(str(line))
       sys.stdout.flush()
+      line=p.stdout.readline().strip()
     print('Done!')
diff --git a/src/pyptlib/manager/serverManager.py b/src/pyptlib/manager/serverManager.py
index 98df2d8..a287ea7 100644
--- a/src/pyptlib/manager/serverManager.py
+++ b/src/pyptlib/manager/serverManager.py
@@ -13,5 +13,4 @@ class ServerManager(Manager):
     
 if __name__=='__main__':
   manager=ServerManager()
-#  manager.launch('src/pyptlib/framework/server.py')
-  manager.launch(['python', '-u', 'test.py'])
\ No newline at end of file
+  manager.launch('src/pyptlib/framework/server.py')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git



More information about the Pkg-privacy-commits mailing list