-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App] Improve pdb for multiprocessing (#15950)
Co-authored-by: thomas <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
15184c6
commit 482b279
Showing
4 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
sklearn | ||
scikit-learn | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import multiprocessing | ||
import os | ||
import pdb | ||
import sys | ||
from typing import Any | ||
|
||
_stdin = [None] | ||
_stdin_lock = multiprocessing.Lock() | ||
try: | ||
_stdin_fd = sys.stdin.fileno() | ||
except Exception: | ||
_stdin_fd = None | ||
|
||
|
||
# Taken from https://github.com/facebookresearch/metaseq/blob/main/metaseq/pdb.py | ||
class MPPdb(pdb.Pdb): | ||
"""debugger for forked programs.""" | ||
"""A Pdb wrapper that works in a multiprocessing environment.""" | ||
|
||
def __init__(self) -> None: | ||
pdb.Pdb.__init__(self, nosigint=True) | ||
|
||
def interaction(self, *args: Any, **kwargs: Any) -> None: | ||
_stdin = sys.stdin | ||
try: | ||
sys.stdin = open("/dev/stdin") | ||
pdb.Pdb.interaction(self, *args, **kwargs) | ||
finally: | ||
sys.stdin = _stdin | ||
def _cmdloop(self) -> None: | ||
stdin_back = sys.stdin | ||
with _stdin_lock: | ||
try: | ||
if _stdin_fd is not None: | ||
if not _stdin[0]: | ||
_stdin[0] = os.fdopen(_stdin_fd) | ||
sys.stdin = _stdin[0] | ||
self.cmdloop() | ||
finally: | ||
sys.stdin = stdin_back | ||
|
||
|
||
def set_trace(*args: Any, **kwargs: Any) -> None: | ||
MPPdb().set_trace(*args, **kwargs) | ||
def set_trace() -> None: | ||
pdb = MPPdb() | ||
pdb.set_trace(sys._getframe().f_back) |