Skip to content

Commit fbf2be7

Browse files
committed
fixup! Giant refactor to move all state into a Kernel struct
1 parent 89aa4cd commit fbf2be7

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/IJulia.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ end
144144
# Variable so that display can be done in the correct Msg context
145145
execute_msg::Msg = Msg(["julia"], Dict("username"=>"jlkernel", "session"=>uuid4()), Dict())
146146
# Variable tracking the number of bytes written in the current execution request
147-
stdio_bytes::RefValue{Int} = Ref(0)
147+
stdio_bytes::Int = 0
148148
# Use an array to accumulate "payloads" for the execute_reply message
149149
execute_payloads::Vector{Dict} = Dict[]
150150

@@ -159,11 +159,16 @@ function Base.setproperty!(kernel::Kernel, name::Symbol, x)
159159
if name (:ans, :n, :In, :Out, :inited)
160160
setproperty!(IJulia, name, x)
161161

162+
# These fields are mirrored to the module the user code executes in, see
163+
# run_kernel().
162164
if name (:ans, :In, :Out)
163165
if hasproperty(kernel.current_module, name)
164166
setproperty!(kernel.current_module, name, x)
165167
end
166168
end
169+
elseif name === :stdio_bytes
170+
# These are Refs
171+
setindex!(getproperty(@__MODULE__, name), x)
167172
end
168173

169174
setfield!(kernel, name, x)
@@ -324,6 +329,9 @@ ans::Any = nothing
324329
"""
325330
n::Int = 0
326331

332+
# Deprecated internal kept around for backwards compatibility
333+
const stdio_bytes = Ref(0)
334+
327335
#######################################################################
328336
# methods to clear history or any subset thereof
329337

@@ -467,7 +475,7 @@ function clear_output(wait=false, kernel=_default_kernel)
467475
empty!(kernel.displayqueue) # discard pending display requests
468476
send_ipython(kernel.publish[], kernel, msg_pub(kernel.execute_msg::Msg, "clear_output",
469477
Dict("wait" => wait)))
470-
kernel.stdio_bytes[] = 0 # reset output throttling
478+
kernel.stdio_bytes = 0 # reset output throttling
471479
return nothing
472480
end
473481

src/execute_request.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function execute_request(socket, kernel, msg)
2727
code = msg.content["code"]
2828
@vprintln("EXECUTING ", code)
2929
kernel.execute_msg = msg
30-
kernel.stdio_bytes[] = 0
30+
kernel.stdio_bytes = 0
3131
silent = msg.content["silent"]
3232
store_history = get(msg.content, "store_history", !silent)
3333
empty!(kernel.execute_payloads)

src/stdio.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ function watch_stream(rd::IO, name::AbstractString, kernel)
7575
while !eof(rd) # blocks until something is available
7676
nb = bytesavailable(rd)
7777
if nb > 0
78-
kernel.stdio_bytes[] += nb
78+
kernel.stdio_bytes += nb
7979
# if this stream has surpassed the maximum output limit then ignore future bytes
80-
if kernel.stdio_bytes[] >= kernel.max_output_per_request[]
80+
if kernel.stdio_bytes >= kernel.max_output_per_request[]
8181
read(rd, nb) # read from libuv/os buffer and discard
82-
if kernel.stdio_bytes[] - nb < kernel.max_output_per_request[]
82+
if kernel.stdio_bytes - nb < kernel.max_output_per_request[]
8383
send_ipython(kernel.publish[], kernel, msg_pub(kernel.execute_msg, "stream",
84-
Dict("name" => "stderr", "text" => "Excessive output truncated after $(kernel.stdio_bytes[]) bytes.")))
84+
Dict("name" => "stderr", "text" => "Excessive output truncated after $(kernel.stdio_bytes) bytes.")))
8585
end
8686
else
8787
@lock buf_lock write(buf, read(rd, nb))

test/kernel.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ end
151151

152152
setproperty!(kernel, field, old_value)
153153
end
154+
155+
@test kernel.stdio_bytes != 42
156+
kernel.stdio_bytes = 42
157+
@test kernel.stdio_bytes == 42
158+
@test IJulia.stdio_bytes[] == 42
154159
end
155160

156161
@testset "Explicit tests with jupyter_client" begin

0 commit comments

Comments
 (0)