<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import click
import redis
import subprocess

import ray.services as services


def check_no_existing_redis_clients(node_ip_address, redis_address):
    redis_ip_address, redis_port = redis_address.split(":")
    redis_client = redis.StrictRedis(host=redis_ip_address,
                                     port=int(redis_port))
    # The client table prefix must be kept in sync with the file
    # "src/common/redis_module/ray_redis_module.cc" where it is defined.
    REDIS_CLIENT_TABLE_PREFIX = "CL:"
    client_keys = redis_client.keys("{}*".format(REDIS_CLIENT_TABLE_PREFIX))
    # Filter to clients on the same node and do some basic checking.
    for key in client_keys:
        info = redis_client.hgetall(key)
        assert b"ray_client_id" in info
        assert b"node_ip_address" in info
        assert b"client_type" in info
        assert b"deleted" in info
        # Clients that ran on the same node but that are marked dead can be
        # ignored.
        deleted = info[b"deleted"]
        deleted = bool(int(deleted))
        if deleted:
            continue

        if info[b"node_ip_address"].decode("ascii") == node_ip_address:
            raise Exception("This Redis instance is already connected to "
                            "clients with this IP address.")


@click.group()
def cli():
    pass


@click.command()
@click.option("--node-ip-address", required=False, type=str,
              help="the IP address of this node")
@click.option("--redis-address", required=False, type=str,
              help="the address to use for connecting to Redis")
@click.option("--redis-port", required=False, type=str,
              help="the port to use for starting Redis")
@click.option("--num-redis-shards", required=False, type=int,
              help=("the number of additional Redis shards to use in "
                    "addition to the primary Redis shard"))
@click.option("--object-manager-port", required=False, type=int,
              help="the port to use for starting the object manager")
@click.option("--num-workers", required=False, type=int,
              help="the initial number of workers to start on this node")
@click.option("--num-cpus", required=False, type=int,
              help="the number of CPUs on this node")
@click.option("--num-gpus", required=False, type=int,
              help="the number of GPUs on this node")
@click.option("--num-custom-resource", required=False, type=int,
              help="the amount of a user-defined custom resource on this node")
@click.option("--head", is_flag=True, default=False,
              help="provide this argument for the head node")
@click.option("--no-ui", is_flag=True, default=False,
              help="provide this argument if the UI should not be started")
@click.option("--block", is_flag=True, default=False,
              help="provide this argument to block forever in this command")
@click.option("--plasma-directory", required=False, type=str,<commit_msg>Document --num-workers better. (#1201)<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import click
import redis
import subprocess

import ray.services as services


def check_no_existing_redis_clients(node_ip_address, redis_address):
    redis_ip_address, redis_port = redis_address.split(":")
    redis_client = redis.StrictRedis(host=redis_ip_address,
                                     port=int(redis_port))
    # The client table prefix must be kept in sync with the file
    # "src/common/redis_module/ray_redis_module.cc" where it is defined.
    REDIS_CLIENT_TABLE_PREFIX = "CL:"
    client_keys = redis_client.keys("{}*".format(REDIS_CLIENT_TABLE_PREFIX))
    # Filter to clients on the same node and do some basic checking.
    for key in client_keys:
        info = redis_client.hgetall(key)
        assert b"ray_client_id" in info
        assert b"node_ip_address" in info
        assert b"client_type" in info
        assert b"deleted" in info
        # Clients that ran on the same node but that are marked dead can be
        # ignored.
        deleted = info[b"deleted"]
        deleted = bool(int(deleted))
        if deleted:
            continue

        if info[b"node_ip_address"].decode("ascii") == node_ip_address:
            raise Exception("This Redis instance is already connected to "
                            "clients with this IP address.")


@click.group()
def cli():
    pass


@click.command()
@click.option("--node-ip-address", required=False, type=str,
              help="the IP address of this node")
@click.option("--redis-address", required=False, type=str,
              help="the address to use for connecting to Redis")
@click.option("--redis-port", required=False, type=str,
              help="the port to use for starting Redis")
@click.option("--num-redis-shards", required=False, type=int,
              help=("the number of additional Redis shards to use in "
                    "addition to the primary Redis shard"))
@click.option("--object-manager-port", required=False, type=int,
              help="the port to use for starting the object manager")
@click.option("--num-workers", required=False, type=int,
              help=("The initial number of workers to start on this node, "
                    "note that the local scheduler may start additional "
                    "workers. If you wish to control the total number of "
                    "concurent tasks, then use --num-cpus instead."))
@click.option("--num-cpus", required=False, type=int,
              help="the number of CPUs on this node")
@click.option("--num-gpus", required=False, type=int,
              help="the number of GPUs on this node")
@click.option("--num-custom-resource", required=False, type=int,
              help="the amount of a user-defined custom resource on this node")
@click.option("--head", is_flag=True, default=False,
              help="provide this argument for the head node")
@click.option("--no-ui", is_flag=True, default=False,
              help="provide this argument if the UI should not be started")
@click.option("--block", is_flag=True, default=False,
              help="provide this argument to block forever in this command")
@click.option("--plasma-directory", required=False, type=str,
{'fraction_non_alphanumeric': 0.10716510903426792, 'fraction_numerical': 0.0006230529595015577, 'mean_word_length': 2.92002442002442, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2203801', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1815, 'n_words': 572}