# Code works when run as a file, but not from REPL

**URL:** https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208
**Category:** General Usage
**Created:** [March 22, 2019, 4:30pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208 "2019-03-22T16:30:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [March 22, 2019, 4:30pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208/1 "2019-03-22T16:30:13Z")

</div>

I have a small piece of code which works perfectly when run as `julia tmp.jl` and even as `julia -e 'include("tmp.jl")'`, but not when I start `julia` and immediately type `include("tmp.jl")`! Neither it works if I just copy-paste the content of `tmp.jl` into fresh julia session.  
Namely, it fails with `ERROR: LoadError: StackOverflowError:` without traceback. So I have no idea how to debug it further from the julia side.  
The code uses `ccall` and `@cfunction` with `$closures` to call a C/Fortran library, so I inserted a bunch of `print`s there for debug. They indicate that the library fails to call a function passed from julia as `@cfunction`, and again not sure how to debug further.

Unfortunately, I cannot provide a simple self-contained example now, as it uses both julia and c/fortran libraries.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [March 22, 2019, 5:06pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208/2 "2019-03-22T17:06:57Z")

</div>

At least show us the Julia code. Are you sure there is no recursive call?

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [March 22, 2019, 5:12pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208/3 "2019-03-22T17:12:24Z")

</div>

Completely sure. The code in `tmp.jl` is very short and everything it does is calling a library:

```julia
using LibProcessTmp
run_process(
    callback = (a, b) -> a == b,
    settings = Settings(size = 2),
)

```

I don’t see anything here to behave differently when run as a file and from repl. Also note, that the execution certainly goes into the library, and even into the wrapped C library, because I inserted prints there. And `@cfunction`s I talk about are defined in the library, not even in this `tmp.jl` file.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 22, 2019, 5:31pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208/4 "2019-03-22T17:31:23Z")

</div>

Sounds a bit like [Initialization of R fails on julia 1.1](https://discourse.julialang.org/t/initialization-of-r-fails-on-julia-1-1/19735/1)

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [March 22, 2019, 7:38pm UTC](https://discourse.julialang.org/t/code-works-when-run-as-a-file-but-not-from-repl/22208/5 "2019-03-22T19:38:17Z")

</div>

Any idea how to debug this?
