def __init__(self, env): self.env = env self.session = None self._tmpdir = None self._sock = None self._proxy = None self._closed = False self._startup_lock = curio.Lock() self._poll_lock = curio.Lock() self._apiVersion_cache = {} self._kind_cache = {} self.healthy = curio.Event()
async def amain(hash_func, a, b=None, num_workers=None): work_queue = curio.Queue() output_lock = curio.Lock() output = {'a': {}} if b: output['b'] = {} hashers = curio.TaskGroup(name='hashers') if not num_workers: try: num_workers = multiprocessing.cpu_count() + 1 except NotImplementedError: num_workers = 2 for _ in range(num_workers): await hashers.spawn(hash_file_worker, work_queue, output, output_lock, hash_func) for fullpath in walk_all_files(a): await work_queue.put(('a', fullpath)) if b: for fullpath in walk_all_files(b): await work_queue.put(('b', fullpath)) await work_queue.join() await hashers.cancel_remaining() return output
async def wait_for_cmd_resp(self, *args): data = self.pack_command(*args) await self.sock.send(data[0]) # lock is not ok, too many waiting event will cause ReadResourceBusy exception async with curio.Lock(): res_data = await self.sock.recv(1024) return res_data
def __init__(self, circuit): self.circuit = circuit # a caproto.VirtualCircuit self.channels = {} # map cid to Channel self.ioids = {} # map ioid to Channel self.ioid_data = {} # map ioid to server response self.subscriptionids = {} # map subscriptionid to Channel self.connected = True self.socket = None self.command_queue = curio.Queue() self.new_command_condition = curio.Condition() self._socket_lock = curio.Lock()
def __init__(self, circuit, client, context): super().__init__(circuit, client, context) self._raw_lock = curio.Lock() self.QueueFull = QueueFull self.command_queue = QueueWithFullError(ca.MAX_COMMAND_BACKLOG) self.new_command_condition = curio.Condition() self.pending_tasks = curio.TaskGroup() self.events_on = curio.Event() self.subscription_queue = QueueWithFullError( ca.MAX_TOTAL_SUBSCRIPTION_BACKLOG) self.write_event = Event()
def __init__( self, *, skt_ctx: Optional["context.BaseSketchContext"] = None) -> None: self._ctx = skt_ctx or context.AsyncioSketchContext() self._skt_cache: Dict[str, sketch.Sketch] = {} if isinstance(self._ctx, context.AsyncioSketchContext): self._find_skt_lock = asyncio.Lock() elif isinstance(self._ctx, context.CurioSketchContext): # noqa: SIM106 self._find_skt_lock = curio.Lock() else: raise RuntimeError("Unknown sketch context.")
async def start_evaluators(params, queue, logger): '''Initialize evaluators and run them. Parameters ---------- params: {str:object} Parameters for initializing evaluators. queue: curio.queue An asynchronous queue to pass data for evaluation. logger: logging.Logger A logger. Returns ------- tasks: [curio.Task] Tasks running the initialized evaluators. ''' lock = curio.Lock() tasks = [] for worker in params: command = worker['command'] tasks.append(await curio.spawn(evaluator(command, queue, lock, logger), daemon=True)) return tasks
def __init__(self, socket: curio.io.Socket) -> None: self.read_lock = curio.Lock() self.write_lock = curio.Lock() self.socket = socket self.stream = socket.as_stream()
def __init__(self) -> None: self._lock = curio.Lock()
def __init__(self, lock=None): if lock is None: self._lock = curio.Condition(curio.Lock()) else: self._lock = curio.Condition(lock._lock)
def __init__(self): self._lock = curio.Lock()
def __init__(self, encoding=False): self._encoding = encoding self._read_write_lock = curio.Lock()
def __init__(self, *args, max_events=None, **kwargs): super().__init__(*args, **kwargs) self.cmd_lock = curio.Lock()
def _lock_factory(self) -> LockLike: return cast(LockLike, curio.Lock())
def __init__(self, f, x0, w0=None, s=augmented_tchebycheff, o=cmaes, d=d0, e=1e-3, max_evals=None): '''Create an AWA object. Parameters ---------- f: callable The vector-valued objective function to optimize. x0: iterable A matrix of initial solutions. The matrix shape determines the problem dimensionality. When the matrix is ``m`` x ``n``, the objective function ``f`` is treated as a map from an n-D space to an m-D space (i.e., m objectives, n variables). w0: iterable, optional A matrix of initial weights. The matrix shape must be ``m`` x ``m`` where the value of ``m`` is determined by the shape of ``x0``. By default, ``np.eye(m)`` is used. s: callable, optional A scalarization function. This function must accept two arguments, a vector-valued objective function ``f`` and a weight ``w``, and returns a scalar-valued objective function. By default, ``augmented_tchebycheff`` function is used. o: callable, optional An optimization function. This function must accept two arguments, a scalar-valued objective function ``f`` and an initial solution ``x``, and returns an optimal solution to ``f``. By default, ``cmaes`` function is used. d: callable, optional A puseudo-distance function. This function must accept two arguments, an address ``a`` and another address ``b``, and returns an puseudo-distance between them. By default, ``d0`` function is used. e: float, optional A tolerance of optimization. This value is used to stop the search for an address. AWA stops the search when d(a, a_old) <= e holds. By default, ``1e-3`` is used. Examples -------- >>> async def f(x): ... return sum(v**2 for v in x), sum((v-1)**2 for v in x) >>> x0 = [[0, 0, 0], ... [1, 1, 1]] >>> awa = AWA(f, x0) ''' self.f = f self.s = s self.o = o self.d = d self.e = e self.max_evals = max_evals if max_evals else {} self.states = {} self.lock = curio.Lock() obj = len(x0) if w0 is None: w0 = np.eye(obj) for a, w, x in zip(AddressSpace(obj, 1), w0, x0): self.states[a] = AWAState(a, w, x)