Skip to content

Commit c29cf42

Browse files
authored
Fix: import pandas before loading in parallel to avoid macOS fork-related errors (#4647)
1 parent aa0c50f commit c29cf42

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

sqlmesh/core/loader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ class Loader(abc.ABC):
164164
"""Abstract base class to load macros and models for a context"""
165165

166166
def __init__(self, context: GenericContext, path: Path) -> None:
167+
# This ensures pandas is imported before any model loading happens in the forked process
168+
# to avoid macOS fork() safety issues, see https://stackoverflow.com/a/52230415. Without
169+
# it, the following error was observerd in a macOS 15.5 system:
170+
#
171+
# "+[NSMutableString initialize] may have been in progress in another thread when fork() was called."
172+
import pandas as pd # noqa
173+
167174
from sqlmesh.core.console import get_console
168175

169176
self._path_mtimes: t.Dict[Path, float] = {}

tests/cli/test_integration_cli.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import shutil
88
import site
99
import uuid
10-
import os
11-
import platform
1210

1311
pytestmark = pytest.mark.slow
1412

@@ -32,11 +30,6 @@ def invoke_cli(tmp_path: Path) -> InvokeCliType:
3230
).stdout.strip()
3331

3432
def _invoke(sqlmesh_args: t.List[str], **kwargs: t.Any) -> subprocess.CompletedProcess:
35-
# Set up environment to handle macOS fork safety, see https://stackoverflow.com/a/52230415
36-
env = os.environ.copy()
37-
if platform.system() == "Darwin":
38-
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
39-
4033
return subprocess.run(
4134
args=[sqlmesh_bin] + sqlmesh_args,
4235
# set the working directory to the isolated temp dir for this test
@@ -46,7 +39,6 @@ def _invoke(sqlmesh_args: t.List[str], **kwargs: t.Any) -> subprocess.CompletedP
4639
# combine stdout/stderr into a single stream
4740
stdout=subprocess.PIPE,
4841
stderr=subprocess.STDOUT,
49-
env=env,
5042
**kwargs,
5143
)
5244

0 commit comments

Comments
 (0)