| 165 | |
| 166 | |
| 167 | def daemonize(args: list[str], executable: Union[str, list[str], None] = None) -> None: |
| 168 | if os.name not in ("posix", "nt"): |
| 169 | return |
| 170 | |
| 171 | if os.environ.get(DVC_DAEMON): |
| 172 | logger.debug("skipping launching a new daemon.") |
| 173 | return |
| 174 | |
| 175 | env = fix_env() |
| 176 | env[DVC_DAEMON] = "1" |
| 177 | if not is_binary(): |
| 178 | file_path = os.path.abspath(inspect.stack()[0][1]) |
| 179 | env["PYTHONPATH"] = os.path.dirname(os.path.dirname(file_path)) |
| 180 | |
| 181 | logger.debug("Trying to spawn %r", args) |
| 182 | pid = _spawn(args, executable, env, output_file=env.get(DVC_DAEMON_LOGFILE)) |
| 183 | logger.debug("Spawned %r with pid %s", args, pid) |