mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
perf python: Allow KeyboardInterrupt to propagate in LiveSession
LiveSession.run() synchronously blocks while polling evlist for events. When running interactive tools or scripts from the terminal, KeyboardInterrupt exceptions raised via Ctrl-C must propagate so the caller can break out of the polling loop. Previously, LiveSession caught KeyboardInterrupt with an empty pass statement, swallowing the exception and preventing calling scripts from detecting the interrupt cleanly. Remove the empty handler so calling scripts receive KeyboardInterrupt and can perform clean teardown. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
f66944587d
commit
ca23ecf8ee
|
|
@ -33,10 +33,16 @@ class LiveSession:
|
|||
# Poll for events with 100ms timeout
|
||||
try:
|
||||
self.evlist.poll(100)
|
||||
# CPython's PyErr_SetFromErrno() invokes PyErr_CheckSignals() on
|
||||
# EINTR, converting SIGINT into KeyboardInterrupt, which inherits
|
||||
# from BaseException rather than InterruptedError/OSError, so
|
||||
# Ctrl-C exits the loop and triggers finally: self.evlist.close()
|
||||
# while non-fatal signals retry poll().
|
||||
except InterruptedError:
|
||||
continue
|
||||
for cpu in self.cpus:
|
||||
for _ in range(1000): # Limit to 1000 events per CPU per poll to prevent starvation
|
||||
# Limit to 1000 events per CPU per poll to prevent starvation
|
||||
for _ in range(1000):
|
||||
try:
|
||||
event = self.evlist.read_on_cpu(cpu)
|
||||
except TypeError as e:
|
||||
|
|
@ -53,7 +59,5 @@ class LiveSession:
|
|||
|
||||
if event.type == perf.RECORD_SAMPLE:
|
||||
self.sample_callback(event)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
self.evlist.close()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user