Commit 1fd0a6f6 authored by Myle Ott's avatar Myle Ott Committed by Facebook Github Bot
Browse files

Fix Pdb

Summary: Pull Request resolved: https://github.com/pytorch/fairseq/pull/551

Differential Revision: D14295227

Pulled By: myleott

fbshipit-source-id: 404f2a2697a62ce0dbf22e5ab2e1cf932acc83ac
parent 88bf8b56
......@@ -14,26 +14,27 @@ import sys
__all__ = ['set_trace']
_stdin_fd = sys.stdin.fileno()
_stdin = [None]
_stdin_lock = multiprocessing.Lock()
class MultiprocessingPdb(pdb.Pdb):
"""A Pdb wrapper that works in a multiprocessing environment.
Usage: `from fairseq import pdb; pdb.set_trace()`
"""
_stdin_fd = sys.stdin.fileno()
_stdin = None
_stdin_lock = multiprocessing.Lock()
def __init__(self):
pdb.Pdb.__init__(self, nosigint=True)
def _cmdloop(self):
stdin_bak = sys.stdin
with self._stdin_lock:
with _stdin_lock:
try:
if not self._stdin:
self._stdin = os.fdopen(self._stdin_fd)
sys.stdin = self._stdin
if not _stdin[0]:
_stdin[0] = os.fdopen(_stdin_fd)
sys.stdin = _stdin[0]
self.cmdloop()
finally:
sys.stdin = stdin_bak
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment