MCPcopy Index your code
hub / github.com/python/cpython / _get_sysctl

Function _get_sysctl

Lib/test/support/socket_helper.py:290–322  ·  view source on GitHub ↗

Get a sysctl value as an integer.

(name)

Source from the content-addressed store, hash-verified

288_sysctl_cache = {}
289
290def _get_sysctl(name):
291 """Get a sysctl value as an integer."""
292 try:
293 return _sysctl_cache[name]
294 except KeyError:
295 pass
296
297 # At least Linux and FreeBSD support the "-n" option
298 cmd = ['sysctl', '-n', name]
299 proc = subprocess.run(cmd,
300 stdout=subprocess.PIPE,
301 stderr=subprocess.STDOUT,
302 text=True)
303 if proc.returncode:
304 support.print_warning(f'{' '.join(cmd)!r} command failed with '
305 f'exit code {proc.returncode}')
306 # cache the error to only log the warning once
307 _sysctl_cache[name] = None
308 return None
309 output = proc.stdout
310
311 # Parse '0\n' to get '0'
312 try:
313 value = int(output.strip())
314 except Exception as exc:
315 support.print_warning(f'Failed to parse {' '.join(cmd)!r} '
316 f'command output {output!r}: {exc!r}')
317 # cache the error to only log the warning once
318 _sysctl_cache[name] = None
319 return None
320
321 _sysctl_cache[name] = value
322 return value
323
324
325def tcp_blackhole():

Callers 1

tcp_blackholeFunction · 0.85

Calls 3

runMethod · 0.45
joinMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…