# External API calls during module \_\_init\_\_. Terrible idea or fine?

**URL:** https://discourse.julialang.org/t/external-api-calls-during-module-init-terrible-idea-or-fine/124998
**Category:** General Usage
**Created:** [January 21, 2025, 7:42am UTC](https://discourse.julialang.org/t/external-api-calls-during-module-init-terrible-idea-or-fine/124998 "2025-01-21T07:42:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [January 21, 2025, 7:42am UTC](https://discourse.julialang.org/t/external-api-calls-during-module-init-terrible-idea-or-fine/124998/1 "2025-01-21T07:42:28Z")

</div>

Hello everyone,

I have the following module:

```julia
module SideEffects

function __init__ ()
 # load_or_fetch! does an API call to a service to retrieve a list
# OR deserialises an object, if the call has already been done
 global MY_DICT = load_or_fetch!(:list)

end

```

I am not sure if this is a terrible idea, but it worked fine with Julia 1.9 and 1.10 (a bit less sure about that). When updating to 1.11, it gets stuck precompiling because of a I/O task in the background:

```julia
Waiting for background task / IO / timer

```

So I have two questions:

- Is there a better way to achieve this?
- Should I just try to have a completely different approach?

It is very convenient to have this list as sort of a “module constant” and be able to do SideEffects.MY\_DICT from multiple places in my code.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [January 21, 2025, 8:50am UTC](https://discourse.julialang.org/t/external-api-calls-during-module-init-terrible-idea-or-fine/124998/2 "2025-01-21T08:50:57Z")

</div>

Is it possible in your context to wrap this external data in an [artifact](https://pkgdocs.julialang.org/v1/artifacts/)? This would be more stable & probably more reproducible than downloading some data during init.

---

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [January 21, 2025, 8:58am UTC](https://discourse.julialang.org/t/external-api-calls-during-module-init-terrible-idea-or-fine/124998/3 "2025-01-21T08:58:56Z")

</div>

Possibly! Somehow I completely forgot about this. I will check it out, thanks for the help.

Perhaps it’s a problem for the update of the artifact itself, perhaps I can work around it.

EDIT: The problem is that in this case maybe it should be immutable and that might be somewhat inconvenient, but I think I should be able to work around it.
