File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change
1
+ Detect proc format eagerly so it throws the error at the correct location.
Original file line number Diff line number Diff line change @@ -67,10 +67,17 @@ class ProcFormatError(EnvironmentError):
67
67
def iter_process_parents (pid , max_depth = 10 ):
68
68
"""Try to look up the process tree via the /proc interface."""
69
69
stat_name = detect_proc ()
70
- for _ in range (max_depth ):
71
- ppid = _get_ppid (pid , stat_name )
72
- args = _get_cmdline (pid )
73
- yield Process (args = args , pid = pid , ppid = ppid )
74
- if ppid == "0" :
75
- break
76
- pid = ppid
70
+
71
+ # Inner generator function so we correctly throw an error eagerly if proc
72
+ # is not supported, rather than on the first call to the iterator. This
73
+ # allows the call site detects the correct implementation.
74
+ def _iter_process_parents (pid , max_depth ):
75
+ for _ in range (max_depth ):
76
+ ppid = _get_ppid (pid , stat_name )
77
+ args = _get_cmdline (pid )
78
+ yield Process (args = args , pid = pid , ppid = ppid )
79
+ if ppid == "0" :
80
+ break
81
+ pid = ppid
82
+
83
+ return _iter_process_parents (pid , max_depth )
You can’t perform that action at this time.
0 commit comments