# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1504860828 -10800
# Node ID e27d253bd0ba1824edfdf754bebeae601cd853cf
# Parent  e31d5a36d1f3cb82117b407747b1cd9277ae8bc8
fix problem if _should_write is called by expired timer after
termination of wx application.

diff -r e31d5a36d1f3 -r e27d253bd0ba BeremizIDE.py
--- a/BeremizIDE.py	Mon Aug 28 10:49:53 2017 +0000
+++ b/BeremizIDE.py	Fri Sep 08 11:53:48 2017 +0300
@@ -163,9 +163,11 @@
             self.TimerAccessLock.release()
 
     def _should_write(self):
-        wx.CallAfter(self._write)
+        app = wx.GetApp()
+        if app is not None:
+            wx.CallAfter(self._write)
+
         if MainThread == currentThread().ident:
-            app = wx.GetApp()
             if app is not None:
                 if self.YieldLock.acquire(0):
                     app.Yield()