I am trying to run a job on a remote process. But the job function will not be run on the main process, so I try to avoid defining it on main process. However, it seems impossible to define a function on a child process if it is not defined on main process first. I am wondering if it is intentional and why.
A minimum example is
using Distributed pid = addprocs(1) ex = :( function foo() println("HI from foo!") end ) # Everything will be fine if I call `eval(ex)` here Distributed.remotecall_eval(Main, pid, ex)
An error is thrown:
LoadError: UndefVarError: #foo not defined
If I call
eval(ex) as stated in the comment, it will define the function on main process and works just like
@everywhere. I understand that it is recommended way, but I do want to know why the example does not work.
The example is tested on Julia 1.6, windows 10.