Index: MLXMANIFEST
===================================================================
--- MLXMANIFEST	(revision 38)
+++ MLXMANIFEST	(revision 38)
@@ -0,0 +1,2 @@
+update1.txt	6	09f7e02f1290be211da707a266f153b3
+runmlx.exe	64000	48360723d8abcd080cddcfb690daef60
Index: src/mlx/gui/gui.py
===================================================================
--- src/mlx/gui/gui.py	(revision 36)
+++ src/mlx/gui/gui.py	(revision 38)
@@ -13,4 +13,6 @@
 
 import time
+import threading
+import sys
 
 acftTypes = [ ("Boeing 737-600", const.AIRCRAFT_B736),
@@ -43,5 +45,10 @@
         self._flight = None
         self._simulator = None
+
+        self._stdioLock = threading.Lock()
+        self._stdioText = ""
         self._stdioAfterNewLine = True
+
+        self.toRestart = False
 
     def build(self, iconDirectory):
@@ -84,5 +91,6 @@
         """Run the GUI."""
         if self._config.autoUpdate:
-            self._updater = Updater(self._programDirectory,
+            self._updater = Updater(self,
+                                    self._programDirectory,
                                     self._config.updateURL,
                                     self._mainWindow)
@@ -185,10 +193,28 @@
             self.showMainWindow()
 
+    def restart(self):
+        """Quit and restart the application."""
+        self.toRestart = True
+        self._quit()
+
+    def flushStdIO(self):
+        """Flush any text to the standard error that could not be logged."""
+        if self._stdioText:
+            sys.__stderr__.write(self._stdioText)
+            
     def writeStdIO(self, text):
         """Write the given text into standard I/O log."""
-        gobject.idle_add(self._writeStdIO, text)
-
-    def _writeStdIO(self, text):
+        with self._stdioLock:
+            self._stdioText += text
+
+        gobject.idle_add(self._writeStdIO)
+
+    def _writeStdIO(self):
         """Perform the real writing."""
+        with self._stdioLock:
+            text = self._stdioText
+            self._stdioText = ""
+        if not text: return
+            
         lines = text.splitlines()
         if text[-1]=="\n":
@@ -335,5 +361,5 @@
         self._quitButton.set_tooltip_text("Quit the program.")
         
-        self._quitButton.connect("clicked", gtk.main_quit)
+        self._quitButton.connect("clicked", self._quit)
 
         setupBox.pack_start(self._quitButton, False, False, 0)
@@ -660,4 +686,9 @@
         self._logView.scroll_mark_onscreen(buffer.get_insert())
 
+    def _quit(self, what = None):
+        """Quit from the application."""
+        self._statusIcon.destroy()
+        return gtk.main_quit()
+
 class TrackerStatusIcon(gtk.StatusIcon):
 	def __init__(self):
Index: src/mlx/gui/statusicon.py
===================================================================
--- src/mlx/gui/statusicon.py	(revision 35)
+++ src/mlx/gui/statusicon.py	(revision 38)
@@ -83,4 +83,14 @@
             self._showHideMenuItem.set_active(True)
 
+    def destroy(self):
+        """Hide and destroy the status icon."""
+        if appIndicator:
+            if pygobject:
+                self._indicator.set_status(appindicator.IndicatorStatus.PASSIVE)
+            else:
+                self._indicator.set_status(appindicator.STATUS_PASSIVE)
+        else:
+            self._statusIcon.set_visible(False)
+        
     def _showHideToggled(self, menuitem):
         """Called when the show/hide menu item is toggled."""
Index: src/mlx/gui/update.py
===================================================================
--- src/mlx/gui/update.py	(revision 37)
+++ src/mlx/gui/update.py	(revision 38)
@@ -5,5 +5,5 @@
 from mlx.gui.common import *
 
-from mlx.update import update, restart
+from mlx.update import update
 
 import mlx.const as const
@@ -96,8 +96,10 @@
                                 else gtk.WIN_POS_CENTER_ON_PARENT)
 
-    def __init__(self, programDirectory, updateURL, parentWindow):
+    def __init__(self, gui, programDirectory, updateURL, parentWindow):
         """Construct the updater. If not created yet, the windows used by the
         updater are also created."""
         super(Updater, self).__init__()
+
+        self._gui = gui
         
         self._programDirectory = programDirectory
@@ -280,5 +282,5 @@
         self._progressWindow.hide()
         if self._restart:
-            restart()
+            self._gui.restart()
 
 #-------------------------------------------------------------------------------
Index: src/mlx/mlx.py
===================================================================
--- src/mlx/mlx.py	(revision 36)
+++ src/mlx/mlx.py	(revision 38)
@@ -7,4 +7,7 @@
 import os
 import sys
+
+if os.name=="nt":
+    import win32api
 
 #--------------------------------------------------------------------------------------
@@ -28,11 +31,24 @@
     config = Config()
     gui = GUI(programDirectory, config)
-
+    
     sys.stdout = StdIOHandler(gui)
     sys.stderr = StdIOHandler(gui)
 
-    gui.build(programDirectory)
+    try:
+        gui.build(programDirectory)
+        
+        gui.run()
+    finally:
+        gui.flushStdIO()
+        sys.stdout = sys.__stdout__
+        sys.stderr = sys.__stderr__
 
-    gui.run()
+    if gui.toRestart:
+        programPath = os.path.join(os.path.dirname(sys.argv[0]),
+                                   "runmlx.exe" if os.name=="nt" else "runmlx.sh")
+        if os.name=="nt":
+            programPath = win32api.GetShortPathName(programPath)
+
+        os.execl(programPath, programPath)
 
 #--------------------------------------------------------------------------------------
Index: src/mlx/update.py
===================================================================
--- src/mlx/update.py	(revision 37)
+++ src/mlx/update.py	(revision 38)
@@ -12,7 +12,4 @@
 import subprocess
 import hashlib
-
-if os.name=="nt":
-    import win32api
 
 #------------------------------------------------------------------------------
@@ -501,14 +498,4 @@
 #------------------------------------------------------------------------------
 
-def restart():
-    """Restart the program."""
-    programPath = os.path.join(os.path.dirname(sys.argv[0]),
-                               "runmlx.exe" if os.name=="nt" else "runmlx.sh")
-    if os.name=="nt":
-        programPath = win32api.GetShortPathName(programPath)
-    os.execl(programPath, programPath)
-        
-#------------------------------------------------------------------------------
-
 def updateProcess():
     """This is called in the child process, when we need a child process."""
