ARM
ARM

Reputation: 1550

How to define a macro everywhere in Julia?

I have a trivial macro

macro lit_str(s)
    s
end

which I am using to generate regex patterns. (Context here). Normally I have this wrapped in a module called HelperFunctions (and export it using ```export @lit_str). I'm trying to use it in a function called via RemoteRef, but even if I do

@everywhere using HelperFunctions

I get an error like

exception on exception on 3: exception on 2: 4: ERROR: @lit_str not defined
 in eval at C:\cygwin\home\vagrant\buildbot\slave\package_win8_1-x64\build\base\sysimg.jl:7
 in anonymous at multi.jl:1305
 in anonymous at multi.jl:855
 in run_work_thunk at multi.jl:621
 in anonymous at task.jl:855
ERROR: @lit_str not defined
 in eval at C:\cygwin\home\vagrant\buildbot\slave\package_win8_1-x64\build\base\sysimg.jl:7
 in anonymous at multi.jl:1305
 in anonymous at multi.jl:855
 in run_work_thunk at multi.jl:621
 in anonymous at task.jl:855
ERROR: @lit_str not defined
 in eval at C:\cygwin\home\vagrant\buildbot\slave\package_win8_1-x64\build\base\sysimg.jl:7
 in anonymous at multi.jl:1305
 in anonymous at multi.jl:855
 in run_work_thunk at multi.jl:621
 in anonymous at task.jl:855

Is there any way to export a macro so it can be used by processes spawned with remoteref?

Upvotes: 2

Views: 227

Answers (1)

ARM
ARM

Reputation: 1550

This was a no-brainer, but I'll put the solution here in case anyone else has the same issue. I needed to do

addprocs(numprocs)

before

@everywhere using WhatNot

since I was doing this in Jupyter and not by calling julia -p 8 myfile.jl.

Upvotes: 5

Related Questions