Is there any reason you can't replace this whole if/elif block with `ip_app.exec_lines = [preexec_source]` and maybe a fallback for old IPython versions? That would also let it run with `ip_app.open_browser = True` and still have the code executed when you start a new notebook.