mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 23:09:55 +01:00
* use popen to run updater/analytics in detached mode subprocess does not provide a way to avoid a zombie process. Not to confuse with orphaned processes, which will be `wait`-ed by `pid 1`. It might not work for long-running processes, but I don't think zombie processes are going to be a problem for us, as the parent process immediately exits after spawning a child process. Even in case of `queue` based experiment runner, parent will exit before than the child process. So I don't think it's a requirement here. But it does feel wrong to leak the processes, so I have to sleep on that. --- This PR: 1. makes `daemonized` process inherit the logging verbosity, so if the parent process used `-vv`, the daemonized process will run the same way. 2. Add `DVC_DAEMON_LOGFILE` envvar, that the daemon will log to the file. By default, the verbosity is the same as running parent processes. Without `DVC_DAEMON_LOGFILE`, the output will be redirected to `/dev/null`. 3. Adds debug/trace for updater/analytics. I hope by doing this, we can make our life easier on debugging and make daemon more transparent/observable. * add tests * fixes * use kwargs * pass all os.environ with some modified
37 lines
1021 B
Python
37 lines
1021 B
Python
import inspect
|
|
import os
|
|
|
|
from dvc import daemon
|
|
|
|
|
|
def test_daemon(mocker):
|
|
mock_windows = mocker.patch("dvc.daemon._spawn_subprocess")
|
|
mock_posix = mocker.patch("dvc.daemon._spawn_posix")
|
|
daemon.daemon(["updater"])
|
|
|
|
if os.name == "nt":
|
|
mock_posix.assert_not_called()
|
|
mock_windows.assert_called()
|
|
args = mock_windows.call_args[0]
|
|
else:
|
|
mock_windows.assert_not_called()
|
|
mock_posix.assert_called()
|
|
args = mock_posix.call_args[0]
|
|
|
|
env = args[2]
|
|
assert "PYTHONPATH" in env
|
|
|
|
file_path = os.path.abspath(inspect.stack()[0][1])
|
|
file_dir = os.path.dirname(file_path)
|
|
test_dir = os.path.dirname(file_dir)
|
|
dvc_dir = os.path.dirname(test_dir)
|
|
assert env["PYTHONPATH"] == dvc_dir
|
|
assert env[daemon.DVC_DAEMON] == "1"
|
|
|
|
|
|
def test_no_recursive_spawn(mocker):
|
|
mocker.patch.dict(os.environ, {daemon.DVC_DAEMON: "1"})
|
|
mock_spawn = mocker.patch("dvc.daemon._spawn")
|
|
daemon.daemon(["updater"])
|
|
mock_spawn.assert_not_called()
|