Commits

Ronny Pfannschmidt  committed a45ad3e

add example, first working version

  • Participants
  • Parent commits 1a2c2f5

Comments (0)

Files changed (2)

+
+import execnet
+import socketpool
+import couchdbkit
+import socketpool_execnetbackend
+
+gw = execnet.makegateway()
+
+backend = socketpool_execnetbackend.ExecnetBackend(gw)
+import sys
+sys.modules['socketpool.backend_execnet'] = backend
+
+server = couchdbkit.Server(backend='execnet')
+
+
+print server.info()

File socketpool_execnetbackend.py

 
 
+import socket
+import threading
 
 def socketmap(*args):
     """
 
 class ExecnetBackend(object):
 
-    import select
-    import socket
-    import threading
-    import time
-    try:
-        import Queue as queue
-    except ImportError: # py3
-        import queue
-    sleep = staticmethod(time.sleep)
-    Semaphore = threading.BoundedSemaphore
-
+    
 
     def __init__(self, gw):
         self.gw = gw
         import sys
         self.chan = gw.remote_exec(sys.modules[__name__])
 
+        import socketpool.backend_thread as t
+        self.t = t
+
+    def __getattr__(self, name):
+        print self, name
+        return getattr(self.t, name)
+
     def Socket(self, *k, **kw):
         self.chan.send(('new', k, kw))
         return RemoteSocket(self.chan.receive())
 
     def Select(self, r, w, x, **kw):
         args, reverse = socketmap(r, w, x)
-        self.chan.send(('select', args, **kw))
+        self.chan.send(('select', args, kw))
         wait = self.chan.receive()
         results = wait.receive()
         return [reverse(x) for x in results]
             socket.close()
             del sockets[chan]
             del channels[socket]
-        method, args, kwargs = args
-        result =getattr(socket,method)(*args, **kwargs)
-        chan.send(result)
+        else:
+            method, args, kwargs = args
+            result =getattr(socket,method)(*args, **kwargs)
+            chan.send(result)
 
     chan.setcallback(socket_data_callback, endmarker=closed)
 
 
 
 
-import socket
-import threading
 
 if __name__ == '__channelexec__':
     sockets = {}
             sockets[chan] = s
             channels[s] = chan
             remote_socket_control(chan)
-        elif command = 'select':
+        elif command == 'select':
             thread = threading.Thread(target=do_select, args=(chan, args), kwargs=kw)
             thread.start()
         channel.send(chan)