From b383e2b4d70333bdd5eaddac6baf8851d26a0063 Mon Sep 17 00:00:00 2001 From: palashahuja Date: Mon, 15 Jan 2018 19:27:31 +0530 Subject: [PATCH] These are changes made for concurrent access. This will deal with the case when the editor is not opening from vim. Simple Concurrent issue when dealing with os.mkstemp --- jrnl/util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jrnl/util.py b/jrnl/util.py index e9df0fb1..933d2e05 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -9,6 +9,7 @@ if "win32" in sys.platform: import colorama colorama.init() import re +import threading import tempfile import subprocess import codecs @@ -126,13 +127,15 @@ def load_and_fix_json(json_path): sys.exit(1) def get_text_from_editor(config, template=""): - _, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt") + fd, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt") with codecs.open(tmpfile, 'w', "utf-8") as f: if template: f.write(template) - subprocess.call(config['editor'].split() + [tmpfile]) + process = subprocess.Popen(config['editor'].split() + [tmpfile]) + process.wait() with codecs.open(tmpfile, "r", "utf-8") as f: raw = f.read() + os.close(fd) os.remove(tmpfile) if not raw: prompt('[Nothing saved to file]')