Module:core.events
Infrastructure for registering and firing callbacks on application events.
UnlikeIPython.core.hooks, which lets end users set single functions tobe called at specific times, or a collection of alternative methods to try,callbacks are designed to be used by extension authors. A number of callbackscan be registered for the same event without needing to be aware of one another.
The functions defined in this module are no-ops indicating the names of availableevents and the arguments which will be passed to them.
Note
This API is experimental in IPython 2.0, and may be revised in future versions.
1 Class
- classIPython.core.events.EventManager(shell:InteractiveShell,available_events:Iterable[str],print_on_error:bool=True)
Bases:
objectManage a collection of events and a sequence of callbacks for each.
This is attached to
InteractiveShellinstances as aneventsattribute.Note
This API is experimental in IPython 2.0, and may be revised in future versions.
- __init__(shell:InteractiveShell,available_events:Iterable[str],print_on_error:bool=True)→None
Initialise the
CallbackManager.- Parameters:
shell – The
InteractiveShellinstanceavailable_events – An iterable of names for callback events.
print_on_error – A boolean flag to set whether the EventManager will print a warning which a event errors.
- register(event:str,function:Callable[[...],Any])→None
Register a new event callback.
- Parameters:
event (str) – The event for which to register this callback.
function (callable) – A function to be called on the given event. It should take the sameparameters as the appropriate callback prototype.
- Raises:
5 Functions
- IPython.core.events.pre_execute()→None
Fires before code is executed in response to user/frontend action.
This includes comm and widget messages and silent execution, as well as usercode cells.
- IPython.core.events.pre_run_cell(info:Any)→None
Fires before user-entered code runs.
- Parameters:
info (
ExecutionInfo) – An object containing information used for the code execution.
- IPython.core.events.post_execute()→None
Fires after code is executed in response to user/frontend action.
This includes comm and widget messages and silent execution, as well as usercode cells.
- IPython.core.events.post_run_cell(result:Any)→None
Fires after user-entered code runs.
- Parameters:
result (
ExecutionResult) – The object which will be returned as the execution result.
- IPython.core.events.shell_initialized(ip:InteractiveShell)→None
Fires after initialisation of
InteractiveShell.This is before extensions and startup scripts are loaded, so it can only beset by subclassing.
- Parameters:
ip (
InteractiveShell) – The newly initialised shell.