Skip to content

Commit bc1c7bb

Browse files
KristofferCmbauman
authored andcommitted
move writing to REPL history file to behind a PID lock
1 parent ee34a68 commit bc1c7bb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

stdlib/REPL/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name = "REPL"
22
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
33

44
[deps]
5+
FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
56
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
67
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
78
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
89
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
910

1011
[extras]
11-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
13+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1314

1415
[targets]
1516
test = ["Test", "Random"]

stdlib/REPL/src/REPL.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Base.Experimental.@max_methods 1
1919

2020
using Base.Meta, Sockets
2121
import InteractiveUtils
22+
import FileWatching
2223

2324
export
2425
AbstractREPL,
@@ -662,7 +663,6 @@ function add_history(hist::REPLHistoryProvider, s::PromptState)
662663
# mode: $mode
663664
$(replace(str, r"^"ms => "\t"))
664665
"""
665-
# TODO: write-lock history file
666666
try
667667
seekend(hist.history_file)
668668
catch err
@@ -671,8 +671,10 @@ function add_history(hist::REPLHistoryProvider, s::PromptState)
671671
# If this doesn't fix it (e.g. when file is deleted), we'll end up rethrowing anyway
672672
hist_open_file(hist)
673673
end
674-
print(hist.history_file, entry)
675-
flush(hist.history_file)
674+
FileWatching.mkpidlock(hist.file_path * ".pid", stale_age=3) do
675+
print(hist.history_file, entry)
676+
flush(hist.history_file)
677+
end
676678
nothing
677679
end
678680

0 commit comments

Comments
 (0)