From d15811da15a53d0701b1f74c1bf9e382c5abc6e0 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Fri, 21 Mar 2025 15:40:48 -0700 Subject: [PATCH 1/2] feat(python): add warning about fork --- python/python/lance/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/python/lance/__init__.py b/python/python/lance/__init__.py index 83b22cf5215..6296dacc1dc 100644 --- a/python/python/lance/__init__.py +++ b/python/python/lance/__init__.py @@ -4,6 +4,8 @@ from __future__ import annotations import logging +import warnings +from os import register_at_fork from typing import TYPE_CHECKING, Dict, Optional, Union from . import log @@ -153,3 +155,13 @@ def set_logger( log_handler=None, ): log.set_logger(file_path, name, level, format_string, log_handler) + + +def __warn_on_fork(): + warnings.warn( + "lance is not fork-safe. If you are using multiprocessing, " + "use spawn instead." + ) + + +register_at_fork(before=__warn_on_fork) From 7b5f6f14d54f0282dce8b53ead275a07c3f06647 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Fri, 21 Mar 2025 16:13:15 -0700 Subject: [PATCH 2/2] try this way --- python/python/lance/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/python/lance/__init__.py b/python/python/lance/__init__.py index 6296dacc1dc..54339c1291a 100644 --- a/python/python/lance/__init__.py +++ b/python/python/lance/__init__.py @@ -4,8 +4,8 @@ from __future__ import annotations import logging +import os import warnings -from os import register_at_fork from typing import TYPE_CHECKING, Dict, Optional, Union from . import log @@ -164,4 +164,5 @@ def __warn_on_fork(): ) -register_at_fork(before=__warn_on_fork) +if hasattr(os, "register_at_fork"): + os.register_at_fork(before=__warn_on_fork)