How to use the uvloop.install function in uvloop

To help you get started, we’ve selected a few uvloop examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github standy66 / purerpc / src / purerpc / anyio_monkeypatch.py View on Github external
def _new_run(func, *args, backend=None, backend_options=None):
    if backend is None:
        backend = os.getenv("PURERPC_BACKEND", "asyncio")
    log.info("Selected {} backend".format(backend))
    if backend == "uvloop":
        import uvloop
        uvloop.install()
        backend = "asyncio"
    return _anyio_run(func, *args, backend=backend, backend_options=backend_options)
github lablup / backend.ai-agent / src / ai / backend / agent / server.py View on Github external
cfg['logging']['endpoint'] = log_endpoint
        try:
            logger = Logger(cfg['logging'], is_master=True, log_endpoint=log_endpoint)
            with logger:
                ns = cfg['etcd']['namespace']
                setproctitle(f"backend.ai: agent {ns}")
                log.info('Backend.AI Agent {0}', VERSION)
                log.info('runtime: {0}', utils.env_info())

                log_config = logging.getLogger('ai.backend.agent.config')
                if debug:
                    log_config.debug('debug mode enabled.')

                if cfg['agent']['event-loop'] == 'uvloop':
                    import uvloop
                    uvloop.install()
                    log.info('Using uvloop as the event loop backend')
                aiotools.start_server(server_main_logwrapper,
                                      num_workers=1,
                                      use_threading=False,
                                      args=(cfg, log_endpoint))
                log.info('exit.')
        finally:
            if cfg['agent']['pid-file'].is_file():
                # check is_file() to prevent deleting /dev/null!
                cfg['agent']['pid-file'].unlink()
    else:
        # Click is going to invoke a subcommand.
        pass
    return 0
github Ehco1996 / aioshadowsocks / shadowsocks / app.py View on Github external
def __init__(self, debug=False):
        if not debug:
            uvloop.install()
        self.loop = asyncio.get_event_loop()
        self.prepared = False
github nitipit / shelfdb / shelfdb / server.py View on Github external
arg = argparse.ArgumentParser(description='ShelfDB Asyncio Server')
    arg.add_argument(
        '--host', nargs='?', type=str, default='127.0.0.1',
        help="server host ip. (default: '127.0.0.1')")
    arg.add_argument(
        '--port', nargs='?', type=int, default=17000,
        help="server port. (default: 17000)")
    arg.add_argument(
        '--db', nargs='?', default='db',
        help="server database directory. (default: 'db')")
    arg = arg.parse_args()
    shelf_server = ShelfServer(arg.host, arg.port, arg.db)

    if sys.platform.startswith('linux'):
        import uvloop
        uvloop.install()

    # Run server until Ctrl+C is pressed
    try:
        asyncio.run(shelf_server.run())
    except KeyboardInterrupt:
        shelf_server.shelfdb.close()
github machinezone / cobra / cobras / runner / __init__.py View on Github external
def main(verbose, profile, uv):
    """\b
   ___      _
  / __\___ | |__  _ __ __ _
 / /  / _ \| '_ \| '__/ _` |
/ /__| (_) | |_) | | | (_| |
\____/\___/|_.__/|_|  \__,_|

Cobra is a realtime messaging server using Python3, WebSockets and Redis.
    """
    if uv:
        uvloop.install()

    if verbose:
        level = 'INFO' if verbose == 1 else 'DEBUG'
        coloredlogs.install(level='INFO', fmt=LOGGING_FORMAT)

    if profile:
        registerProfiler()
github vapor-ware / synse-server / synse_server / __main__.py View on Github external
def main() -> None:
    uvloop.install()
    asyncio.set_event_loop(uvloop.new_event_loop())

    parser = argparse.ArgumentParser(
        description='API server for the Synse platform',
    )
    parser.add_argument(
        '--host', required=False, default='0.0.0.0', type=str,
        help='the host/ip for the server to listen on',
    )
    parser.add_argument(
        '--port', required=False, default=5000, type=int,
        help='the port for the server to listen on',
    )
    parser.add_argument(
        '--version', required=False, action='store_true',
        help='print the version',
github aleph-im / pyaleph / src / aleph / commands.py View on Github external
def main(args):
    """Main entry point allowing external calls

    Args:
      args ([str]): command line parameter list
    """

    uvloop.install()
    args = parse_args(args)
    setup_logging(args.loglevel)
    LOGGER.info("Starting up.")

    config = Config(schema=get_defaults())
    app['config'] = config
    app.config = config

    config.aleph.port.value = args.port
    config.aleph.host.value = args.host

    if args.config_file is not None:
        app['config'].yaml.load(args.config_file)

    model.init_db(config, ensure_indexes=(not args.debug))
    LOGGER.info("Database initialized.")
github abersheeran / websocks / client.py View on Github external
import logging
import logging.config
import threading

import websockets
from websockets import WebSocketClientProtocol

logger: logging.Logger = logging.getLogger("websocks")

# use IOCP in windows
if sys.platform == 'win32' and (sys.version_info.major >= 3 and sys.version_info.minor >= 7):
    asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
# try to use uvloop
try:
    import uvloop
    uvloop.install()
except ImportError:
    pass


#########################
# Error
#########################

class Socks5Error(Exception):
    pass


class WebSocksError(Exception):
    pass
github hail-is / hail / batch / batch / batch.py View on Github external
REQUEST_TIME_POST_CREATE_BATCH = REQUEST_TIME.labels(endpoint='/api/v1alpha/batches/create', verb='POST')
REQUEST_TIME_POST_GET_BATCH = REQUEST_TIME.labels(endpoint='/api/v1alpha/batches/batch_id', verb='GET')
REQUEST_TIME_PATCH_CANCEL_BATCH = REQUEST_TIME.labels(endpoint='/api/v1alpha/batches/batch_id/cancel', verb="PATCH")
REQUEST_TIME_PATCH_CLOSE_BATCH = REQUEST_TIME.labels(endpoint='/api/v1alpha/batches/batch_id/close', verb="PATCH")
REQUEST_TIME_DELETE_BATCH = REQUEST_TIME.labels(endpoint='/api/v1alpha/batches/batch_id', verb="DELETE")
REQUEST_TIME_GET_BATCH_UI = REQUEST_TIME.labels(endpoint='/batches/batch_id', verb='GET')
REQUEST_TIME_POST_CANCEL_BATCH_UI = REQUEST_TIME.labels(endpoint='/batches/batch_id/cancel', verb='POST')
REQUEST_TIME_GET_BATCHES_UI = REQUEST_TIME.labels(endpoint='/batches', verb='GET')
REQUEST_TIME_GET_LOGS_UI = REQUEST_TIME.labels(endpoint='/batches/batch_id/jobs/job_id/log', verb="GET")
REQUEST_TIME_GET_POD_STATUS_UI = REQUEST_TIME.labels(endpoint='/batches/batch_id/jobs/job_id/pod_status', verb="GET")

POD_EVICTIONS = pc.Counter('batch_pod_evictions', 'Count of batch pod evictions')
PVC_CREATION_FAILURES = pc.Counter('batch_pvc_creation_failures', 'Count of batch pvc creation failures')
READ_POD_LOG_FAILURES = pc.Counter('batch_read_pod_log_failures', 'Count of batch read_pod_log failures')

uvloop.install()

log.info(f'KUBERNETES_TIMEOUT_IN_SECONDS {KUBERNETES_TIMEOUT_IN_SECONDS}')
log.info(f'REFRESH_INTERVAL_IN_SECONDS {REFRESH_INTERVAL_IN_SECONDS}')
log.info(f'HAIL_POD_NAMESPACE {HAIL_POD_NAMESPACE}')
log.info(f'POD_VOLUME_SIZE {POD_VOLUME_SIZE}')
log.info(f'INSTANCE_ID = {INSTANCE_ID}')
log.info(f'BATCH_IMAGE = {BATCH_IMAGE}')
log.info(f'MAX_PODS = {MAX_PODS}')
log.info(f'QUEUE_SIZE = {QUEUE_SIZE}')

deploy_config = get_deploy_config()

STORAGE_CLASS_NAME = 'batch'

if 'BATCH_USE_KUBE_CONFIG' in os.environ:
    kube.config.load_kube_config()