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()
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
def picklable(v): try: pickle.dumps(v, pickle.HIGHEST_PROTOCOL) return True except Exception: return False
def respond(cookie, data): res = pickle.dumps((cookie, data), 2) header = struct.pack('<cI', op, len(res)) with sock_lock: sock.sendall(header + res)