Commits

Ronny Pfannschmidt committed a9cce5a

more work on Select

Comments (0)

Files changed (2)

 
 import execnet
-import socketpool
+import socketpool.pool
 import couchdbkit
 import socketpool_execnetbackend
 
 import sys
 sys.modules['socketpool.backend_execnet'] = backend
 
-server = couchdbkit.Server(backend='execnet')
+
+pool = socketpool.ConnectionPool(
+    socketpool_execnetbackend.connector_type(),
+    backend='execnet' )
+
+server = couchdbkit.Server(pool=pool)
 
 
 print server.info()
+print server.all_dbs()

socketpool_execnetbackend.py

 
-
+import select
 import socket
 import threading
 
         result.append(arglist)
     return result, mapping.get
 
+
+
+
+def connector_type():
+    import restkit.conn
+    class Conn(restkit.conn.Connection):
+        def is_connected(self):
+            r, _, _ = self.backend_mod.Select([self._s], [], [], timeout=0)
+            return not r
+    return Conn
+
+
 class ExecnetBackend(object):
 
-    
-
     def __init__(self, gw):
         self.gw = gw
         import sys
         self.chan.send(('select', args, kw))
         wait = self.chan.receive()
         results = wait.receive()
-        return [reverse(x) for x in results]
+        returns = []
+        for res in results:
+            returns.append([reverse(x) for x in res])
+        return returns
 
 
 
             del channels[socket]
         else:
             method, args, kwargs = args
+            chan.gateway._trace("socket call", socket, method, args, kwargs)
             result =getattr(socket,method)(*args, **kwargs)
             chan.send(result)
 
     args = []
     for list in lists:
         args.append([sockets[x] for x in list])
-    results = select(*args, **kw)
+    if 'timeout' in kw:
+        args.append(kw.get('timeout'))
+    try:
+        results = select.select(*args)
+    except:
+        #XXX: error
+        chan.send(([],[],[]))
+        return
     send = []
     for res in results:
-        sent.append([channels[s] for s in res])
+        send.append([channels[s] for s in res])
     chan.send(send)