From 290f2bd6ed19298d49c3dc53f43a14f50e64cdee Mon Sep 17 00:00:00 2001 From: xzackli Date: Tue, 21 Apr 2020 13:24:09 -0400 Subject: [PATCH 1/2] delay init if delay_init_until_cell is true --- src/init.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/init.jl b/src/init.jl index 9fd1fffb..ae72ccbc 100644 --- a/src/init.jl +++ b/src/init.jl @@ -174,13 +174,18 @@ end # declare more globals created in __init__ const isjulia_display = Ref(true) +const delay_init_until_cell = Ref(false) version = v"0.0.0" backend = "Agg" gui = :default # initialization -- anything that depends on Python has to go here, # so that it occurs at runtime (while the rest of PyPlot can be precompiled). -function __init__() +function init() + if !ispynull(plt) + return # we already initialized + end + isjulia_display[] = isdisplayok() copy!(matplotlib, pyimport_conda("matplotlib", "matplotlib")) mvers = matplotlib.__version__ @@ -222,6 +227,14 @@ function __init__() init_colormaps() end +function __init__() + if delay_init_until_cell[] && ("JPY_PARENT_PID" in keys(ENV)) + Main.IJulia.push_preexecute_hook(init) # delay init until cell execution if Jupyter + else + init() + end +end + function pygui(b::Bool) if !b != isjulia_display[] if backend != "Agg" From adbf6c5508c4a438c6fa6cebbdc55c937ee1b140 Mon Sep 17 00:00:00 2001 From: xzackli Date: Wed, 16 Dec 2020 17:29:03 -0500 Subject: [PATCH 2/2] remove environmental variable use --- src/init.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.jl b/src/init.jl index ae72ccbc..2d71dc89 100644 --- a/src/init.jl +++ b/src/init.jl @@ -228,7 +228,7 @@ function init() end function __init__() - if delay_init_until_cell[] && ("JPY_PARENT_PID" in keys(ENV)) + if delay_init_until_cell[] Main.IJulia.push_preexecute_hook(init) # delay init until cell execution if Jupyter else init()