Cannot document @everywhere function

It seems I can not document and put the @everywhere annotation at the same time.

The following code

"""
Prints something
"""
@everywhere function my_func()
  println("hello")
end

throws the error

ERROR: LoadError: cannot document the following expression:

#= /path/test.jl:4 =# @everywhere function my_func()
        #= /path/test.jl:4 =#
        #= /path/test.jl:5 =#
        println("hello")
    end

'@everywhere' not documentable. See 'Base.@__doc__' docs for details.

Stacktrace:
 [1] error(::String, ::String) at ./error.jl:42
 [2] top-level scope at /path/test.jl:1
 [3] include(::String) at ./client.jl:457
 [4] top-level scope at REPL[8]:1
in expression starting at /path/test.jl:1

Is there a workaround for this ?

1 Like

I think you can do:

julia> f(x) = 1
f (generic function with 1 method)

julia> @everywhere f

But please report is as bug at Issues · JuliaLang/julia · GitHub, if it hasn’t yet been reported.

@mauro3 I can’t get this to work. In this case the function is not defined on the remote worker.

I use this script

"""
Prints something
"""
function my_func()
  println("hello")
end

@everywhere my_func

@fetchfrom workers()[1] my_func()

And it gives

ERROR: LoadError: On worker 2:
UndefVarError: my_func not defined

I execute this with julia -p 4 and include("test.jl")

I created the issue on github btw

you can try to separate docstring declaration from function definition like that:

"""
Prints something
"""
function my_func end

@everywhere my_func()
  println("hello")
end
4 Likes

@pbayer This works, thank you !

1 Like

You can simply write:

@everywhere """
DOCSTRING
"""
function foo()
    println("hello")
end

And it should work perfectly fine.

Also you can wrap your code in begin...end blocks like this:

@everywhere begin
"""
DOCSTRING
"""
function foo()
    println("hello")
end
end
3 Likes