Skip to content

Commit fa415b8

Browse files
Separate socket locks into send & recv locks
1 parent 7d1030e commit fa415b8

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
julia-version: ['1.6', '1']
14+
julia-version: ['1.10', '1']
1515
julia-arch: [x64]
1616
os: [ubuntu-latest, windows-latest, macOS-13]
1717
include:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ JSON = "0.18,0.19,0.20,0.21,1"
2727
MbedTLS = "0.5,0.6,0.7,1"
2828
SoftGlobalScope = "1"
2929
ZMQ = "1"
30-
julia = "1.6"
30+
julia = "1.10"

src/init.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const heartbeat = Ref{Socket}()
2828
const profile = Dict{String,Any}()
2929
const read_stdout = Ref{Base.PipeEndpoint}()
3030
const read_stderr = Ref{Base.PipeEndpoint}()
31-
const socket_locks = Dict{Socket,ReentrantLock}()
31+
const socket_locks_recv = Dict{Socket,ReentrantLock}()
32+
const socket_locks_send = Dict{Socket,ReentrantLock}()
3233

3334
# needed for executing pkg commands on earlier Julia versions
3435
@static if VERSION < v"1.11"
@@ -97,8 +98,9 @@ function init(args)
9798

9899
# associate a lock with each socket so that multi-part messages
99100
# on a given socket don't get inter-mingled between tasks.
100-
for s in (publish[], raw_input[], requests[], control[], heartbeat[])
101-
socket_locks[s] = ReentrantLock()
101+
for s in (publish[], raw_input[], requests[], control[])
102+
socket_locks_send[s] = ReentrantLock()
103+
socket_locks_recv[s] = ReentrantLock()
102104
end
103105

104106
start_heartbeat(heartbeat[])

src/msg.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ function show(io::IO, msg::Msg)
4141
end
4242

4343
function send_ipython(socket, m::Msg)
44-
lock(socket_locks[socket])
45-
try
44+
@lock socket_locks_send[socket] begin
4645
@vprintln("SENDING ", m)
4746
for i in m.idents
4847
send(socket, i, more=true)
@@ -57,14 +56,11 @@ function send_ipython(socket, m::Msg)
5756
send(socket, parent_header, more=true)
5857
send(socket, metadata, more=true)
5958
send(socket, content)
60-
finally
61-
unlock(socket_locks[socket])
6259
end
6360
end
6461

6562
function recv_ipython(socket)
66-
lock(socket_locks[socket])
67-
try
63+
@lock socket_locks_recv[socket] begin
6864
idents = String[]
6965
s = recv(socket, String)
7066
@vprintln("got msg part $s")
@@ -85,8 +81,6 @@ function recv_ipython(socket)
8581
m = Msg(idents, JSON.parse(header), JSON.parse(content), JSON.parse(parent_header), JSON.parse(metadata))
8682
@vprintln("RECEIVED $m")
8783
return m
88-
finally
89-
unlock(socket_locks[socket])
9084
end
9185
end
9286

0 commit comments

Comments
 (0)