What callbacks/hooks exist in Base/stdlibs

What hook exist in Base/Core/stdlibs?

By hooks I mean places you can register an arbitrary function to run whenever something occurs.

Ones I am aware of out of hand:

  • finalizer(f, x) runs when object x has no program-accessible references
  • atexit runs when julia exits (docs)
  • atreplinit runs just prior to when the REPL inializes (docs)
  • Base.package_callbacks runs whenever a module (or is it package?) is loaded (docs

Are there any others?

(and: no, I don’t intend to use this for evil. Would I do something like that?)

12 Likes
  • The REPL’s ast_transforms, used by many packages
  • Base.update_stackframes_callback, used by e.g. AbbreviatedStackTraces
  • Base.methodloc_callback, used by Revise
4 Likes

I believe that, when run, Base.set_active_project(...) will call callbacks.

I don’t remember off the top of my head how those callbacks are registered.

Revise also uses Base.include_callbacks, which AFAIU contains a list of callbacks that are run when any file is included somewhere.

1 Like

See “Other global state in Base”

1 Like