Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pdb in the child process by ensuring stdin is fd 0 #15

Merged
merged 1 commit into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/hupper/ipc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

from .compat import WIN

Expand Down Expand Up @@ -54,7 +55,10 @@ def recv_fd(pipe, mode):
if 'a' in mode:
flags |= os.O_APPEND
fd = msvcrt.open_osfhandle(handle, flags)
return os.fdopen(fd, mode)
return fd

def patch_stdin(fd):
sys.stdin = os.fdopen(fd, 'r')

def snapshot_termios(fd):
pass
Expand All @@ -75,7 +79,15 @@ def send_fd(pipe, fd, pid):

def recv_fd(pipe, mode):
fd = pipe.recv()
return os.fdopen(fd, mode)
return fd

def patch_stdin(fd):
# Python's input() function used by pdb and other things only uses
# readline if stdin matches the stdin file descriptor that the
# process started with (0). Since multiprocessing closes it already
# we can just dup the new fd over it.
os.dup2(fd, 0)
sys.stdin = os.fdopen(0, 'r')

def snapshot_termios(fd):
if os.isatty(fd):
Expand Down
4 changes: 3 additions & 1 deletion src/hupper/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .interfaces import IReloaderProxy
from .ipc import (
dup_fd,
patch_stdin,
recv_fd,
send_fd,
snapshot_termios,
Expand Down Expand Up @@ -237,7 +238,8 @@ def worker_main(spec, files_queue, pipe, parent_pipe, spec_args=None,
signal.signal(signal.SIGHUP, signal.SIG_IGN)

# use the stdin fd passed in from the reloader process
sys.stdin = recv_fd(pipe, 'r')
stdin_fd = recv_fd(pipe, 'r')
patch_stdin(stdin_fd)

# disable pyc files for project code because it can cause timestamp
# issues in which files are reloaded twice
Expand Down