Skip to content

Commit 7487b8f

Browse files
KristofferCKristofferCIanButterworthmbauman
authored
move writing to REPL history file to behind a PID lock (#45450)
Should fix #37015 --------- Co-authored-by: KristofferC <[email protected]> Co-authored-by: Ian Butterworth <[email protected]> Co-authored-by: Matt Bauman <[email protected]>
1 parent 2fd8343 commit 7487b8f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

stdlib/REPL/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
33
version = "1.11.0"
44

55
[deps]
6+
FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
67
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
78
JuliaSyntaxHighlighting = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
89
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

stdlib/REPL/src/REPL.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
using Base.Meta, Sockets, StyledStrings
4242
using JuliaSyntaxHighlighting
4343
import InteractiveUtils
44+
import FileWatching
4445

4546
export
4647
AbstractREPL,
@@ -927,7 +928,6 @@ function add_history(hist::REPLHistoryProvider, s::PromptState)
927928
# mode: $mode
928929
$(replace(str, r"^"ms => "\t"))
929930
"""
930-
# TODO: write-lock history file
931931
try
932932
seekend(hist.history_file)
933933
catch err
@@ -936,8 +936,15 @@ function add_history(hist::REPLHistoryProvider, s::PromptState)
936936
# If this doesn't fix it (e.g. when file is deleted), we'll end up rethrowing anyway
937937
hist_open_file(hist)
938938
end
939-
print(hist.history_file, entry)
940-
flush(hist.history_file)
939+
if isfile(hist.file_path)
940+
FileWatching.mkpidlock(hist.file_path * ".pid", stale_age=3) do
941+
print(hist.history_file, entry)
942+
flush(hist.history_file)
943+
end
944+
else # handle eg devnull
945+
print(hist.history_file, entry)
946+
flush(hist.history_file)
947+
end
941948
nothing
942949
end
943950

0 commit comments

Comments
 (0)