# Using project environments, possible bug

**URL:** <https://discourse.julialang.org/t/using-project-environments-possible-bug/21744>\
**Category:** General Usage\
**Created:** [March 11, 2019, 2:48pm UTC](https://discourse.julialang.org/t/using-project-environments-possible-bug/21744 "2019-03-11T14:48:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwabeke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwabeke/32/4005_2.png) [@lwabeke](https://discourse.julialang.org/u/lwabeke)\
**Post date:** [March 11, 2019, 2:48pm UTC](https://discourse.julialang.org/t/using-project-environments-possible-bug/21744/1 "2019-03-11T14:48:42Z")

</div>

I am trying to create a new project environment, however it seems that when I activate that environment, I cause Julia to segfault.  
Am I doing anything wrong, or is this a bug? I’m happy to log a bug somewhere, but not sure where it goes? I suspect it it related to what the Memento package is doing, but Memento seems to work fine if I don’t create

The below seems to be a minimalworking example.

```julia
]generate minworkExample
]activate minworkExample
]add Memento

```

Which gave me a Project.toml file containing:

```julia
name = "minworkExample"
uuid = "64b62c9e-38f1-11e9-32f6-b10192221abf"
authors = ["Leon Wabeke <lwabeke@csir.co.za>"]
version = "0.1.0"

[deps]
Memento = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"

```

I can supply the Manifest.toml if required, but leaving it out for the sake of space of this post

edit src/minworkExample.jl to contain:

```julia
module minworkExample

using Memento

greet() = print("Hello World!")

function minTest()
notice(logger, "Test message")
end

logger = Memento.config!("debug"; fmt="[{date} | {level} | {name}]: {msg}")

end # module

```

The running:

```julia
julia> using minworkExample
julia> minworkExample.greet()
julia> minworkExample.minTest()

```

Causes a crash with:

```julia
signal (11): Segmentation fault
in expression starting at no file:0
uv_write2 at /buildworker/worker/package_linux64/build/deps/srccache/libuv-2348256acf5759a544e5ca7935f638d2bc091d60/src/unix/stream.c:1434
jl_uv_write at /buildworker/worker/package_linux64/build/src/jl_uv.c:442
uv_write_async at ./stream.jl:877
uv_write at ./stream.jl:845
unsafe_write at ./stream.jl:901
macro expansion at ./gcutils.jl:87 [inlined]
write at ./strings/io.jl:165 [inlined]
print at ./strings/io.jl:167 [inlined]
#with_output_color#671 at ./util.jl:384
#with_output_color at ./none:0 [inlined]
#printstyled#672 at ./util.jl:398 [inlined]
#printstyled at ./none:0
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
emit at /home/msr-rx/.julia/packages/Memento/QMKyB/src/handlers.jl:190
log at /home/msr-rx/.julia/packages/Memento/QMKyB/src/handlers.jl:46
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
log at /home/msr-rx/.julia/packages/Memento/QMKyB/src/loggers.jl:342
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
_log at /home/msr-rx/.julia/packages/Memento/QMKyB/src/loggers.jl:387
log at /home/msr-rx/.julia/packages/Memento/QMKyB/src/loggers.jl:366 [inlined]
notice at /home/msr-rx/.julia/packages/Memento/QMKyB/src/loggers.jl:402 [inlined]
minTest at /home/msr-rx/tmp/minworkExample/src/minworkExample.jl:8
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:323
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:411
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:362 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f5757379f4f)
unknown function (ip: (nil))
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:894
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:764
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:793
eval at ./boot.jl:328
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]
#26 at ./task.jl:259
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:572
unknown function (ip: 0xffffffffffffffff)
Allocations: 8564167 (Pool: 8562506; Big: 1661); GC: 18
Segmentation fault (core dumped)

```

However using it without activating the environment seems to work fine (and both seems to have the same version of the Memento package [f28f55f0] Memento v0.10.0) :

```julia
julia> include("minworkExample/src/minworkExample.jl")
Main.minworkExample

julia> using Main.minworkExample

julia> Main.minworkExample.greet()
Hello World!
julia> Main.minworkExample.minTest()
[2019-03-11 16:43:22 | notice | root]: Test message

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [March 11, 2019, 3:02pm UTC](https://discourse.julialang.org/t/using-project-environments-possible-bug/21744/2 "2019-03-11T15:02:56Z")

</div>

This happens because of your global variable `logger`, which presumably contains some pointers, in combination with precompilation. Consider something like this instead:

```julia
module minworkExample

using Memento

greet() = print("Hello World!")

function minTest()
    notice(logger[], "Test message")
end

const logger = Ref{Memento.Logger}()

function __init__ ()
    logger[] = Memento.config!("debug"; fmt="[{date} | {level} | {name}]: {msg}")
end

end # module

```

Alternatively turn off precompilation for your module with ` __precompile__ (false)`.

---

<div class="post-metadata">

**Author:** ![lwabeke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwabeke/32/4005_2.png) [@lwabeke](https://discourse.julialang.org/u/lwabeke)\
**Post date:** [March 11, 2019, 3:09pm UTC](https://discourse.julialang.org/t/using-project-environments-possible-bug/21744/3 "2019-03-11T15:09:04Z")

</div>

Thanks, that makes sense.  
I will give the **init** a try.

The one part of my reason for looking at this is to maintain a stable environment to deploy and use for a long period of time.  
The other part of looking at this to utilise precompilation in an attempt to work around the other problem I have (see [Unnecessary compilation happening on every call - #7 by lwabeke](https://discourse.julialang.org/t/unnecessary-compilation-happening-on-every-call/17558/7) )
