Skip to content

Commit

Permalink
fix console appearing on daemon in Windows (iterative#6450)
Browse files Browse the repository at this point in the history
* fix console appearing on daemon in Windows

* fix entrypoint
  • Loading branch information
skshetry authored Aug 25, 2021
1 parent 60d4b47 commit 73811f6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@

logger = logging.getLogger(__name__)

CREATE_NEW_PROCESS_GROUP = 0x00000200
DETACHED_PROCESS = 0x00000008
CREATE_NO_WINDOW = 0x08000000 # only available since Python 3.7 in subprocess.


def _popen(cmd, **kwargs):
prefix = [sys.executable]
if not is_binary():
prefix += [sys.argv[0]]

main_entrypoint = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "__main__.py"
)
prefix += [main_entrypoint]
return Popen(prefix + cmd, close_fds=True, shell=False, **kwargs)


def _spawn_windows(cmd, env):
from subprocess import STARTF_USESHOWWINDOW, STARTUPINFO
from subprocess import (
CREATE_NEW_PROCESS_GROUP,
STARTF_USESHOWWINDOW,
STARTUPINFO,
)

creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
# https://stackoverflow.com/a/7006424
# https://bugs.python.org/issue41619
creationflags = CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW

startupinfo = STARTUPINFO()
startupinfo.dwFlags |= STARTF_USESHOWWINDOW

_popen(
cmd, env=env, creationflags=creationflags, startupinfo=startupinfo
).communicate()
_popen(cmd, env=env, creationflags=creationflags, startupinfo=startupinfo)


def _spawn_posix(cmd, env):
Expand Down

0 comments on commit 73811f6

Please sign in to comment.