MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

Lib/multiprocessing/resource_tracker.py:346–420  ·  view source on GitHub ↗

Run resource tracker.

(fd)

Source from the content-addressed store, hash-verified

344
345
346def main(fd):
347 '''Run resource tracker.'''
348 # protect the process from ^C and "killall python" etc
349 signal.signal(signal.SIGINT, signal.SIG_IGN)
350 signal.signal(signal.SIGTERM, signal.SIG_IGN)
351 if _HAVE_SIGMASK:
352 signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
353
354 for f in (sys.stdin, sys.stdout):
355 try:
356 f.close()
357 except Exception:
358 pass
359
360 cache = {rtype: set() for rtype in _CLEANUP_FUNCS.keys()}
361 exit_code = 0
362
363 try:
364 # keep track of registered/unregistered resources
365 with open(fd, 'rb') as f:
366 for line in f:
367 try:
368 cmd, rtype, name = _decode_message(line)
369 cleanup_func = _CLEANUP_FUNCS.get(rtype, None)
370 if cleanup_func is None:
371 raise ValueError(
372 f'Cannot register {name} for automatic cleanup: '
373 f'unknown resource type {rtype}')
374
375 if cmd == 'REGISTER':
376 cache[rtype].add(name)
377 elif cmd == 'UNREGISTER':
378 cache[rtype].remove(name)
379 elif cmd == 'PROBE':
380 pass
381 else:
382 raise RuntimeError('unrecognized command %r' % cmd)
383 except Exception:
384 exit_code = 3
385 try:
386 sys.excepthook(*sys.exc_info())
387 except:
388 pass
389 finally:
390 # all processes have terminated; cleanup any remaining resources
391 for rtype, rtype_cache in cache.items():
392 if rtype_cache:
393 try:
394 exit_code = 1
395 if rtype == 'dummy':
396 # The test 'dummy' resource is expected to leak.
397 # We skip the warning (and *only* the warning) for it.
398 pass
399 else:
400 warnings.warn(
401 f'resource_tracker: There appear to be '
402 f'{len(rtype_cache)} leaked {rtype} objects to '
403 f'clean up at shutdown: {rtype_cache}'

Callers

nothing calls this directly

Calls 12

setFunction · 0.85
_decode_messageFunction · 0.85
lenFunction · 0.85
openFunction · 0.50
closeMethod · 0.45
keysMethod · 0.45
getMethod · 0.45
addMethod · 0.45
removeMethod · 0.45
itemsMethod · 0.45
warnMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected