Skip to content

Commit

Permalink
Revert "Fixed daemon detection to determine forking behavior" (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao authored Sep 17, 2024
1 parent f7c7d0a commit aedc65c
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions sqlmesh/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations

import datetime
import multiprocessing as mp
import os
import sys
import typing as t
from pathlib import Path

Expand Down Expand Up @@ -32,27 +32,11 @@
"""Maximum number of characters in a model definition"""


def is_daemon_process() -> bool:
"""
Determines whether the current process is running as a daemon (background process).
This function checks if the standard output (stdout) is connected to a terminal.
It does this by calling `sys.stdout.fileno()` to retrieve the file descriptor
for the stdout stream and `os.isatty()` to check if this file descriptor is
associated with a terminal device.
Returns:
bool: True if the process is running as a daemon (not attached to a terminal),
False if the process is running in a terminal (interactive mode).
"""
return not os.isatty(sys.stdout.fileno())


# The maximum number of fork processes, used for loading projects
# None means default to process pool, 1 means don't fork, :N is number of processes
# Factors in the number of available CPUs even if the process is bound to a subset of them
# (e.g. via taskset) to avoid oversubscribing the system and causing kill signals
if hasattr(os, "fork") and not is_daemon_process():
if hasattr(os, "fork") and not mp.current_process().daemon:
try:
MAX_FORK_WORKERS: t.Optional[int] = int(os.getenv("MAX_FORK_WORKERS")) # type: ignore
except TypeError:
Expand Down Expand Up @@ -97,6 +81,7 @@ def is_daemon_process() -> bool:
SQLMESH_BUILTIN = "__sqlmesh__builtin__"
SQLMESH_METADATA = "__sqlmesh__metadata__"


BUILTIN = "builtin"
AIRFLOW = "airflow"
DBT = "dbt"
Expand Down

0 comments on commit aedc65c

Please sign in to comment.