Is it possible to detect if Julia is ahead-of-time precompiling?

I’d like to be able to tell at run-time (in __init__() in a package) whether the package is being “ahead-of-time precompiled” or not, in the sense that Pkg.precompile() is running (or similarly if precompiling automatically after Pkg.add() etc.). It needs to ignore “just-in-time precompilation” where a package is precompiled just before being imported into user code. Is this possible?

The use-case here is that PythonCall does a lot of stuff (installing Python and packages etc.) in __init__() which can be skipped if the package is not actually being imported. In fact, it doesn’t even make sense to install Python and packages during this ahead-of-time precompilation.

As a bonus, this would work around this weird bug during AOT-precompilation of a package depending on PythonCall on Windows.

is_precompiling() = ccall(:jl_generating_output, Cint, ()) == 1

It’d be nice to have this in Base (even if unexported) instead of relying on an undocumented ccall that propagates through the package ecosystem by word of mouth.