from socket import SocketType as _SocketType
from typing import Any, TypeVar

_T = TypeVar('_T')

__version__: str

class Runtime:
    _clock: int
    _closed: bool
    _sigset: list[int]
    _sig_wfd: Any
    _sig_listening: bool
    _ssock_r: Any
    _ssock_w: Any
    _stopping: bool

    def __init__(
        self, threads: int, threads_blocking: int, threads_blocking_timeout: int, context: bool, signals: list[int]
    ): ...
    def _run(self): ...
    def _spawn_pygen(self, coro): ...
    def _spawn_pyasyncgen(self, coro): ...
    def _spawn_blocking(self, f, *args, **kwargs) -> tuple[BlockingTaskCtl, Event, ResultHolder]: ...
    def _io_event_r(self, fd: int) -> Event: ...
    def _io_event_w(self, fd: int) -> Event: ...
    def _sig_add(self, sig: int) -> Event: ...
    def _sig_rem(self, sig: int) -> bool: ...

class Waiter:
    def __init__(self, *events: Event): ...

class Event:
    def __init__(self): ...
    def set(self): ...
    def clear(self): ...
    def is_set(self) -> bool: ...
    def waiter(self, timeout: int | None) -> Waiter: ...

class ResultHolder:
    def __init__(self, size: int = 1): ...
    def store(self, value, index: int | None = None): ...
    def fetch(self): ...

class Scope:
    def __init__(self): ...
    def _incr(self, val: int) -> bool: ...
    def _track_pygen(self, coro) -> Event: ...
    def _track_pyasyncgen(self, coro) -> Event: ...
    def _stack(self) -> tuple[Waiter, list[Any]]: ...
    def cancel(self) -> bool: ...

class BlockingTaskCtl:
    def abort(self): ...

class Lock:
    def acquire(self) -> None | Event: ...
    def try_acquire(self): ...
    def release(self): ...

class LockCtx:
    def __init__(self, lock: Lock): ...
    def __enter__(self): ...
    def __exit__(self, exc_type, exc_value, exc_tb): ...

class Semaphore:
    def __init__(self, value: int): ...
    def acquire(self) -> None | Event: ...
    def try_acquire(self): ...
    def release(self): ...
    def tokens(self) -> int: ...

class SemaphoreCtx:
    def __init__(self, semaphore: Semaphore): ...
    def __enter__(self): ...
    def __exit__(self, exc_type, exc_value, exc_tb): ...

class Barrier:
    _event: Event

    def __init__(self, value: int): ...
    def ack(self) -> int: ...
    def value(self) -> int: ...

class Channel:
    def __init__(self, size: int): ...

class ChannelSender:
    def __init__(self, channel: Channel): ...
    def _send(self, message) -> Event: ...
    def close(self): ...

class ChannelReceiver[_T]:
    def __init__(self, channel: Channel): ...
    def _receive(self) -> tuple[Event, bool, _T]: ...

class UnboundedChannel:
    def __init__(self): ...

class UnboundedChannelSender[_T]:
    def __init__(self, channel: UnboundedChannel): ...
    def send(self, message: _T): ...

class UnboundedChannelReceiver[_T]:
    def __init__(self, channel: UnboundedChannel): ...
    def _receive(self) -> tuple[Event, bool, _T]: ...

class CancelledError(BaseException): ...
class ResourceBroken(Exception): ...
class RuntimeAlreadyInitializedError(RuntimeError): ...
class RuntimeNotInitializedError(RuntimeError): ...
class TimeoutError(BaseException): ...
class WouldBlock(Exception): ...

class Socket:
    _sock: _SocketType

    def __init__(self, stdlib_socket: _SocketType): ...
    def _eof_get(self) -> bool: ...
    def _eof_set(self): ...

class TLSStream:
    _state: int

    def _handshake_pre(self): ...
    def _handshake_post(self): ...
    def _set_broken(self): ...
    def _set_closed(self): ...
    def _check_ready(self): ...

def get_runtime() -> Runtime: ...
def set_runtime(runtime: Runtime): ...
