python/ray/__init__.py
def _configure_system():
    import os
    import platform
    import sys

    """Wraps system configuration to avoid 'leaking' variables into ray."""

    # Sanity check pickle5 if it has been installed.
    if "pickle5" in sys.modules:
        if sys.version_info >= (3, 8):
            logger.warning(
                "Package pickle5 becomes unnecessary in Python 3.8 and above. "
                "Its presence may confuse libraries including Ray. "
                "Please uninstall the package."
            )

        import pkg_resources

        try:
            version_info = pkg_resources.require("pickle5")
            version = tuple(int(n) for n in version_info[0].version.split("."))
            if version < (0, 0, 10):
                logger.warning(
                    "Although not used by Ray, a version of pickle5 that leaks memory "
                    "is found in the environment. Please run 'pip install pickle5 -U' "
                    "to upgrade."
                )
        except pkg_resources.DistributionNotFound:
            logger.warning(
                "You are using the 'pickle5' module, but "
                "the exact version is unknown (possibly carried as "
                "an internal component by another module). Please "
                "make sure you are using pickle5 >= 0.0.10 because "
                "previous versions may leak memory."
            )

    # MUST add pickle5 to the import path because it will be imported by some
    # raylet modules.
    #
    # When running Python version < 3.8, Ray needs to use pickle5 instead of
    # Python's built-in pickle. Add the directory containing pickle5 to the
    # Python path so that we find the pickle5 version packaged with Ray and
    # not a pre-existing pickle5.
    if sys.version_info < (3, 8):
        pickle5_path = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "pickle5_files"
        )
        sys.path.insert(0, pickle5_path)

    # Check that grpc can actually be imported on Apple Silicon. Some package
    # managers (such as `pip`) can't properly install the grpcio library yet,
    # so provide a proactive error message if that's the case.
    if platform.system() == "Darwin" and platform.machine() == "arm64":
        try:
            import grpc  # noqa: F401
        except ImportError:
            raise ImportError(
                "Failed to import grpc on Apple Silicon. On Apple"
                " Silicon machines, try `pip uninstall grpcio; conda "
                "install grpcio`. Check out "
                "https://docs.ray.io/en/master/ray-overview/installation.html"
                "#m1-mac-apple-silicon-support for more details."
            )

    if "OMP_NUM_THREADS" not in os.environ:
        logger.debug(
            "[ray] Forcing OMP_NUM_THREADS=1 to avoid performance "
            "degradation with many workers (issue #6998). You can "
            "override this by explicitly setting OMP_NUM_THREADS."
        )
        os.environ["OMP_NUM_THREADS"] = "1"

    # Importing psutil & setproctitle. Must be before ray._raylet is
    # initialized.
    thirdparty_files = os.path.join(
        os.path.abspath(os.path.dirname(__file__)), "thirdparty_files"
    )
    sys.path.insert(0, thirdparty_files)

    if (
        platform.system() == "Linux"
        and "Microsoft".lower() in platform.release().lower()
    ):
        import ray._private.compat  # noqa: E402

        ray._private.compat.patch_psutil()

    # Expose ray ABI symbols which may be dependent by other shared
    # libraries such as _streaming.so. See BUILD.bazel:_raylet
    python_shared_lib_suffix = ".so" if sys.platform != "win32" else ".pyd"
    so_path = os.path.join(
        os.path.dirname(__file__), "_raylet" + python_shared_lib_suffix
    )
    if os.path.exists(so_path):
        import ctypes
        from ctypes import CDLL

        CDLL(so_path, ctypes.RTLD_GLOBAL)
Wraps system configuration to avoid 'leaking' variables into ray.
Wraps system configuration to avoid 'leaking' variables into ray.
Wraps system configuration to avoid ' leaking ' variables into ray .
def _configure_system():
    import os
    import platform
    import sys
    if "pickle5" in sys.modules:
        if sys.version_info >= (3, 8):
            logger.warning(
                "Package pickle5 becomes unnecessary in Python 3.8 and above. "
                "Its presence may confuse libraries including Ray. "
                "Please uninstall the package."
            )
        import pkg_resources
        try:
            version_info = pkg_resources.require("pickle5")
            version = tuple(int(n) for n in version_info[0].version.split("."))
            if version < (0, 0, 10):
                logger.warning(
                    "Although not used by Ray, a version of pickle5 that leaks memory "
                    "is found in the environment. Please run 'pip install pickle5 -U' "
                    "to upgrade."
                )
        except pkg_resources.DistributionNotFound:
            logger.warning(
                "You are using the 'pickle5' module, but "
                "the exact version is unknown (possibly carried as "
                "an internal component by another module). Please "
                "make sure you are using pickle5 >= 0.0.10 because "
                "previous versions may leak memory."
            )
     When running Python version < 3.8, Ray needs to use pickle5 instead of
     Python's built-in pickle. Add the directory containing pickle5 to the
     Python path so that we find the pickle5 version packaged with Ray and
     not a pre-existing pickle5.
    if sys.version_info < (3, 8):
        pickle5_path = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "pickle5_files"
        )
        sys.path.insert(0, pickle5_path)
     Check that grpc can actually be imported on Apple Silicon. Some package
     managers (such as `pip`) can't properly install the grpcio library yet,
     so provide a proactive error message if that's the case.
    if platform.system() == "Darwin" and platform.machine() == "arm64":
        try:
            import grpc   noqa: F401
        except ImportError:
            raise ImportError(
                "Failed to import grpc on Apple Silicon. On Apple"
                " Silicon machines, try `pip uninstall grpcio; conda "
                "install grpcio`. Check out "
                "https://docs.ray.io/en/master/ray-overview/installation.html"
                "m1-mac-apple-silicon-support for more details."
            )
    if "OMP_NUM_THREADS" not in os.environ:
        logger.debug(
            "[ray] Forcing OMP_NUM_THREADS=1 to avoid performance "
            "degradation with many workers (issue 6998). You can "
            "override this by explicitly setting OMP_NUM_THREADS."
        )
        os.environ["OMP_NUM_THREADS"] = "1"
     Importing psutil & setproctitle. Must be before ray._raylet is
     initialized.
    thirdparty_files = os.path.join(
        os.path.abspath(os.path.dirname(__file__)), "thirdparty_files"
    )
    sys.path.insert(0, thirdparty_files)
    if (
        platform.system() == "Linux"
        and "Microsoft".lower() in platform.release().lower()
    ):
        import ray._private.compat   noqa: E402
        ray._private.compat.patch_psutil()
     Expose ray ABI symbols which may be dependent by other shared
     libraries such as _streaming.so. See BUILD.bazel:_raylet
    python_shared_lib_suffix = ".so" if sys.platform != "win32" else ".pyd"
    so_path = os.path.join(
        os.path.dirname(__file__), "_raylet" + python_shared_lib_suffix
    )
    if os.path.exists(so_path):
        import ctypes
        from ctypes import CDLL
        CDLL(so_path, ctypes.RTLD_GLOBAL)
def _configure_system ( ) : import os import platform import sys if "pickle5" in sys . modules : if sys . version_info >= ( 3 , 8 ) : logger . warning ( "Package pickle5 becomes unnecessary in Python 3.8 and above. " "Its presence may confuse libraries including Ray. " "Please uninstall the package." ) import pkg_resources try : version_info = pkg_resources . require ( "pickle5" ) version = tuple ( int ( n ) for n in version_info [ 0 ] . version . split ( "." ) ) if version < ( 0 , 0 , 10 ) : logger . warning ( "Although not used by Ray, a version of pickle5 that leaks memory " "is found in the environment. Please run 'pip install pickle5 -U' " "to upgrade." ) except pkg_resources . DistributionNotFound : logger . warning ( "You are using the 'pickle5' module, but " "the exact version is unknown (possibly carried as " "an internal component by another module). Please " "make sure you are using pickle5 >= 0.0.10 because " "previous versions may leak memory." ) if sys . version_info < ( 3 , 8 ) : pickle5_path = os . path . join ( os . path . abspath ( os . path . dirname ( __file__ ) ) , "pickle5_files" ) sys . path . insert ( 0 , pickle5_path ) if platform . system ( ) == "Darwin" and platform . machine ( ) == "arm64" : try : import grpc except ImportError : raise ImportError ( "Failed to import grpc on Apple Silicon. On Apple" " Silicon machines, try `pip uninstall grpcio; conda " "install grpcio`. Check out " "https://docs.ray.io/en/master/ray-overview/installation.html" "#m1-mac-apple-silicon-support for more details." ) if "OMP_NUM_THREADS" not in os . environ : logger . debug ( "[ray] Forcing OMP_NUM_THREADS=1 to avoid performance " "degradation with many workers (issue #6998). You can " "override this by explicitly setting OMP_NUM_THREADS." ) os . environ [ "OMP_NUM_THREADS" ] = "1" thirdparty_files = os . path . join ( os . path . abspath ( os . path . dirname ( __file__ ) ) , "thirdparty_files" ) sys . path . insert ( 0 , thirdparty_files ) if ( platform . system ( ) == "Linux" and "Microsoft" . lower ( ) in platform . release ( ) . lower ( ) ) : import ray . _private . compat ray . _private . compat . patch_psutil ( ) python_shared_lib_suffix = ".so" if sys . platform != "win32" else ".pyd" so_path = os . path . join ( os . path . dirname ( __file__ ) , "_raylet" + python_shared_lib_suffix ) if os . path . exists ( so_path ) : import ctypes from ctypes import CDLL CDLL ( so_path , ctypes . RTLD_GLOBAL )
Wraps system configuration to avoid 'leaking' variables into ray.
Wraps system configuration to avoid ' leaking ' variables into ray .
"""Wraps system configuration to avoid 'leaking' variables into ray.""" # Sanity check pickle5 if it has been installed. # MUST add pickle5 to the import path because it will be imported by some # raylet modules. # # When running Python version < 3.8, Ray needs to use pickle5 instead of # Python's built-in pickle. Add the directory containing pickle5 to the # Python path so that we find the pickle5 version packaged with Ray and # not a pre-existing pickle5. # Check that grpc can actually be imported on Apple Silicon. Some package # managers (such as `pip`) can't properly install the grpcio library yet, # so provide a proactive error message if that's the case. # noqa: F401 # Importing psutil & setproctitle. Must be before ray._raylet is # initialized. # noqa: E402 # Expose ray ABI symbols which may be dependent by other shared # libraries such as _streaming.so. See BUILD.bazel:_raylet