diff --git a/distributed/scheduler.py b/distributed/scheduler.py index f9c409bf00..ed7b832ef3 100644 --- a/distributed/scheduler.py +++ b/distributed/scheduler.py @@ -97,8 +97,15 @@ try: import line_profiler + profile = line_profiler.LineProfiler() - atexit.register(profile.dump_stats, f"prof_{os.getpid()}.lstat") + + def dump_stats(p): + s = p.get_stats() + if any(s.timings.values()): + profile.dump_stats(f"prof_{os.getpid()}.lstat") + + atexit.register(dump_stats, profile) except ImportError: def profile(func): return func