예제 #1
0
 def _do(self, op, data):
     with self._lock:
         cookie = self.cookie
         self.cookie += 1
         # have to register waiter before we send packet (to avoid a race)
         waiter = self._waiter(cookie)
         data = pickle.dumps((cookie, data), 2)
         header = struct.pack('<cI', op, len(data))
         self.sock.sendall(header + data)
     # must wait without the lock, otherwise all this threading gets us nothing.
     return waiter()
예제 #2
0
 def _do(self, op, data):
     with self._lock:
         cookie = self.cookie
         self.cookie += 1
         # have to register waiter before we send packet (to avoid a race)
         waiter = self._waiter(cookie)
         data = pickle.dumps((cookie, data), 2)
         header = struct.pack('<cI', op, len(data))
         self.sock.sendall(header + data)
     # must wait without the lock, otherwise all this threading gets us nothing.
     res = waiter()
     if res is None:
         raise Exception("Runner exited unexpectedly.")
     return res
예제 #3
0
 def picklable(v):
     try:
         pickle.dumps(v, pickle.HIGHEST_PROTOCOL)
         return True
     except Exception:
         return False
예제 #4
0
def respond(cookie, data):
    res = pickle.dumps((cookie, data), 2)
    header = struct.pack('<cI', op, len(res))
    with sock_lock:
        sock.sendall(header + res)