Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

multiprocessing_pdb.py 1.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  1. # Copyright (c) 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the LICENSE file in
  5. # the root directory of this source tree. An additional grant of patent rights
  6. # can be found in the PATENTS file in the same directory.
  7. import multiprocessing
  8. import os
  9. import pdb
  10. import sys
  11. class MultiprocessingPdb(pdb.Pdb):
  12. """A Pdb wrapper that works in a multiprocessing environment.
  13. Usage: `from fairseq import pdb; pdb.set_trace()`
  14. """
  15. _stdin_fd = sys.stdin.fileno()
  16. _stdin = None
  17. _stdin_lock = multiprocessing.Lock()
  18. def __init__(self):
  19. pdb.Pdb.__init__(self, nosigint=True)
  20. def _cmdloop(self):
  21. stdin_bak = sys.stdin
  22. with self._stdin_lock:
  23. try:
  24. if not self._stdin:
  25. self._stdin = os.fdopen(self._stdin_fd)
  26. sys.stdin = self._stdin
  27. self.cmdloop()
  28. finally:
  29. sys.stdin = stdin_bak
  30. pdb = MultiprocessingPdb()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...