# Closure not shipping to remote workers except from Main?

**URL:** https://discourse.julialang.org/t/closure-not-shipping-to-remote-workers-except-from-main/38831
**Category:** General Usage
**Tags:** closure
**Created:** [May 5, 2020, 8:45pm UTC](https://discourse.julialang.org/t/closure-not-shipping-to-remote-workers-except-from-main/38831 "2020-05-05T20:45:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [May 5, 2020, 8:45pm UTC](https://discourse.julialang.org/t/closure-not-shipping-to-remote-workers-except-from-main/38831/1 "2020-05-05T20:45:39Z")

</div>

Consider the following code which generates a closure via an `@eval` (needed in my non-MWE), and then ships it to a remote worker to evaluate:

```julia
module Foo

using Distributed

make_closure(x) = @eval let x=$x; () -> x; end

function fetch_λ()
    λ = make_closure(1)
    @fetch λ()
end

end

```

Trying to use this, it errors with:

```julia
julia> using Distributed

julia> addprocs(1)
1-element Array{Int64,1}:
 2

julia> using Foo

julia> Foo.fetch_λ()
ERROR: On worker 2:
UndefVarError: #3#4 not defined

```

However, if I switch `@eval` to `@eval Main` to eval the closure in `Main`, then it works. Does anyone know why this is happening and/or if its a bug?

I’m aware that globals in Main are automatically shipped to workers, but here it don’t see how that applies, since `λ` is a local variable inside of my `fetch_λ` function. Thanks for any help.
