From b74a2f4e45925b69dad416f3979e6c7a6056cd8a Mon Sep 17 00:00:00 2001 From: chase Date: Fri, 28 Aug 2020 12:10:43 -0400 Subject: [PATCH] Add small delay before unlinking file in external viewer fixes #4152 In some cases, such as with firefox, the file is removed before the viewer is finished loading. --- CHANGELOG | 1 + mitmproxy/tools/console/master.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 78dd1788c..7644ec8ab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ Unreleased: mitmproxy next * Revamp onboarding app (@mhils) * Add ASGI support for embedded apps (@mhils) * Updated raw exports to not remove headers (@wchasekelley) + * Fix file unlinking before external viewer finishes loading (@wchasekelley) * --- TODO: add new PRs above this line --- diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 6ab9ba5a2..ab1d84142 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -11,6 +11,7 @@ import sys import tempfile import typing # noqa import contextlib +import threading import urwid @@ -171,7 +172,9 @@ class ConsoleMaster(master.Master): signals.status_message.send( message="Can't start external viewer: %s" % " ".join(c) ) - os.unlink(name) + # small delay before removing the file + t = threading.Timer(1.0, os.unlink, args=[name]) + t.start() def set_palette(self, opts, updated): self.ui.register_palette(