From 0dfacce662379eb12aa0d9ac68e51ee66d266954 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 5 May 2019 16:16:18 -0400 Subject: [PATCH 1/2] [idle] When saving a file, call flush and fsync This came up during today's final PyCon keynote -- IDLE was called out as one of the two editors *not* to use when live-coding on Adafruit's Circuit Playground Express (https://www.adafruit.com/product/3333). I *think* that the problem referred to is that IDLE doesn't guarantee that the bits are actually flushed to disk -- they may linger in the OS filesystem cache. And I *think* this PR fixes the issue. I've tested that this doesn't break things, but I don't have the right cable around so I cannot test this with the hardware handed out to PyCon attendees until Wednesday at the earliest. --- Lib/idlelib/iomenu.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index f5bced597aa821..b9e813be0630e2 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -384,6 +384,8 @@ def writefile(self, filename): try: with open(filename, "wb") as f: f.write(chars) + f.flush() + os.fsync(f.fileno()) return True except OSError as msg: tkMessageBox.showerror("I/O Error", str(msg), From 41083935c99f38b0fd2694219c212df0f1b1c284 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 5 May 2019 16:28:11 -0400 Subject: [PATCH 2/2] Add blurb --- Misc/NEWS.d/next/IDLE/2019-05-05-16-27-53.bpo-13102.AGNWYJ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/IDLE/2019-05-05-16-27-53.bpo-13102.AGNWYJ.rst diff --git a/Misc/NEWS.d/next/IDLE/2019-05-05-16-27-53.bpo-13102.AGNWYJ.rst b/Misc/NEWS.d/next/IDLE/2019-05-05-16-27-53.bpo-13102.AGNWYJ.rst new file mode 100644 index 00000000000000..18b31b1fe50572 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-05-05-16-27-53.bpo-13102.AGNWYJ.rst @@ -0,0 +1 @@ +When saving a file, call os.flush() so bits are flushed to e.g. USB drive.