|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import datetime |
| 4 | +import multiprocessing as mp |
4 | 5 | import os |
5 | | -import sys |
6 | 6 | import typing as t |
7 | 7 | from pathlib import Path |
8 | 8 |
|
|
32 | 32 | """Maximum number of characters in a model definition""" |
33 | 33 |
|
34 | 34 |
|
35 | | -def is_daemon_process() -> bool: |
36 | | - """ |
37 | | - Determines whether the current process is running as a daemon (background process). |
38 | | -
|
39 | | - This function checks if the standard output (stdout) is connected to a terminal. |
40 | | - It does this by calling `sys.stdout.fileno()` to retrieve the file descriptor |
41 | | - for the stdout stream and `os.isatty()` to check if this file descriptor is |
42 | | - associated with a terminal device. |
43 | | -
|
44 | | - Returns: |
45 | | - bool: True if the process is running as a daemon (not attached to a terminal), |
46 | | - False if the process is running in a terminal (interactive mode). |
47 | | - """ |
48 | | - return not os.isatty(sys.stdout.fileno()) |
49 | | - |
50 | | - |
51 | 35 | # The maximum number of fork processes, used for loading projects |
52 | 36 | # None means default to process pool, 1 means don't fork, :N is number of processes |
53 | 37 | # Factors in the number of available CPUs even if the process is bound to a subset of them |
54 | 38 | # (e.g. via taskset) to avoid oversubscribing the system and causing kill signals |
55 | | -if hasattr(os, "fork") and not is_daemon_process(): |
| 39 | +if hasattr(os, "fork") and not mp.current_process().daemon: |
56 | 40 | try: |
57 | 41 | MAX_FORK_WORKERS: t.Optional[int] = int(os.getenv("MAX_FORK_WORKERS")) # type: ignore |
58 | 42 | except TypeError: |
@@ -97,6 +81,7 @@ def is_daemon_process() -> bool: |
97 | 81 | SQLMESH_BUILTIN = "__sqlmesh__builtin__" |
98 | 82 | SQLMESH_METADATA = "__sqlmesh__metadata__" |
99 | 83 |
|
| 84 | + |
100 | 85 | BUILTIN = "builtin" |
101 | 86 | AIRFLOW = "airflow" |
102 | 87 | DBT = "dbt" |
|
0 commit comments