# Loading User Modules in wrong order causes a freeze without errors

**URL:** <https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 20, 2018, 11:55am UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848 "2018-12-20T11:55:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 11:55am UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/1 "2018-12-20T11:55:34Z")

</div>

Hello,

I have the following problem with my julia setup. I have about 10 user modules and they depend on each other and also on other mackages.

Now, when I load specific modules, e. g. with

```julia
using A
using B
using C

```

everything works. But changing the order, e. g.

```julia
using C
using A
using B

```

causes julia to freeze forever without any errors or warnings.

I place this question as a very general one because it would be a huge example when I would show you my real case or it would take a very long time to figure out a simple test case where it happens.

My questions are:

1. how can I try to figure out what is going on here,
2. does anyone has the same issue,
3. is there a general rule on how modules are not allowed to depend on each other,
4. is the order also important for performance?

Would be happy to discuss this issue with you. Thanks.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 20, 2018, 12:15pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/2 "2018-12-20T12:15:26Z")

</div>

No, it should generally be safe to load modules in whatever order you want. I would suggest trying to create a minimal example: pick a module, comment out half of the code, and see if the freeze still occurs. Then repeat until you can’t remove any more code without fixing the freeze, and post what’s left here.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [December 20, 2018, 12:33pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/3 "2018-12-20T12:33:23Z")

</div>

Are you sure it is freezed and not just taking a long time ? Have you waited up to 10 minutes ?  
There is an issue with packages loading taking a very long time when they are loading in a certain order:  
[https://github.com/JuliaLang/julia/issues/28425#issuecomment-412268997](https://github.com/JuliaLang/julia/issues/28425#issuecomment-412268997)  
As a rule of thumb, the best way to avoid this issue is to to a topological sort and first load the package that are dependencies of other packages and then load the packages depending on them.

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 1:57pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/4 "2018-12-20T13:57:48Z")

</div>

No, I have just waited over 10 minutes and still no luck. I will try to find out, which part of the code causes the freeze.

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 1:59pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/5 "2018-12-20T13:59:09Z")

</div>

Hello, I found a code which, when excluded, removed the problem, however, I am not able to create a minimal example which reproduces the error without the rest of the files

The code is

```julia
Base.show(io::IO, T::Fit, args...; kwargs...) = println(io, string(T, args...; kwargs...))
Base.println(io::IO, T::Fit, args...; kwargs...) = println(io, string(T, args...; kwargs...))

```

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [December 20, 2018, 2:02pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/6 "2018-12-20T14:02:00Z")

</div>

Are you using Julia v1.0.3 ? There have been a lot of fixes in that release.

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 2:03pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/7 "2018-12-20T14:03:15Z")

</div>

No, I am on 1.0.2 and I have quite a lot of issues with my code not running with 1.0.2. Before that I was using 1.0.0. Could you imagine it would help to upgrade?

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 2:44pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/8 "2018-12-20T14:44:41Z")

</div>

I have tested with 1.0.3 and the result is the same.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 20, 2018, 3:29pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/9 "2018-12-20T15:29:40Z")

</div>

Ah, that’s very useful information. The default implementation for `string()` internally uses `show()`, so your `show()` definition looks like it’s very likely to cause a stack overflow. Even worse, your `show()` calls `println`, which also calls `string()` which also probably calls `show()`, resulting in even more stack overflow goodness.

It’s possible that Julia is failing to compile that code, or that it’s simply stuck in a stack overflow trying to even print out your type.

Unless you’ve defined `Base.string(::Fit)` somewhere, then you should actually do the string conversion in `Base.show`. For example, I would suggest replacing both of those lines with:

```julia
Base.show(io::IO, T::Fit) = print(io, "This is a Fit")

```

---

<div class="post-metadata">

**Author:** ![stakaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stakaz/32/4740_2.png) [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Post date:** [December 20, 2018, 3:32pm UTC](https://discourse.julialang.org/t/loading-user-modules-in-wrong-order-causes-a-freeze-without-errors/18848/10 "2018-12-20T15:32:20Z")

</div>

> [@rdeits](#):
>
> Base.string(::Fit)

I have defined this in the module. The funny thing is that this module compiles just fine. But when `using ThisModule` is the followed with the next user module, than I do get the freeze. However, I still should look at how to define show and println probably.
