Skip to content

Commit 3db96b6

Browse files
committed
Add env var to shut down kernel immediately after start for benchmarking
Setting IPYKERNEL_BENCHMARK_STARTUP_SHUTDOWN stops the event loop right after it starts, so total process wall-clock time measures kernel startup without needing an actual client to send a shutdown request. This can be used in conjunction with -X importtime and profile viewer like tuna to work on speeding up importing and starting a kernel
1 parent 342cf58 commit 3db96b6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

ipykernel/kernelapp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ def start(self):
755755
self.poller.start()
756756
self.kernel.start()
757757
self.io_loop = ioloop.IOLoop.current()
758+
if os.environ.get("IPYKERNEL_BENCHMARK_STARTUP_SHUTDOWN"):
759+
# Shut down immediately after entering the event loop, for
760+
# benchmarking kernel startup time end-to-end.
761+
self.io_loop.add_callback(self.io_loop.stop)
758762
if self.trio_loop:
759763
from ipykernel.trio_runner import TrioRunner
760764

0 commit comments

Comments
 (0)