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

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-detect-if-julia-is-ahead-of-time-precompiling/78631>\
**Category:** General Usage\
**Tags:** precompilation\
**Created:** [March 28, 2022, 6:07pm UTC](https://discourse.julialang.org/t/is-it-possible-to-detect-if-julia-is-ahead-of-time-precompiling/78631 "2022-03-28T18:07:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [March 28, 2022, 6:07pm UTC](https://discourse.julialang.org/t/is-it-possible-to-detect-if-julia-is-ahead-of-time-precompiling/78631/1 "2022-03-28T18:07:24Z")

</div>

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](https://github.com/cjdoris/PythonCall.jl/issues/136) during AOT-precompilation of a package depending on PythonCall on Windows.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [March 28, 2022, 6:13pm UTC](https://discourse.julialang.org/t/is-it-possible-to-detect-if-julia-is-ahead-of-time-precompiling/78631/2 "2022-03-28T18:13:27Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [March 28, 2022, 6:32pm UTC](https://discourse.julialang.org/t/is-it-possible-to-detect-if-julia-is-ahead-of-time-precompiling/78631/3 "2022-03-28T18:32:15Z")

</div>

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.
