Index: src/mlx/acft.py
===================================================================
--- src/mlx/acft.py	(revision 150)
+++ src/mlx/acft.py	(revision 152)
@@ -202,10 +202,4 @@
                                     "Block time: " +
                                     util.getTimeIntervalString(blockLength))
-                bookedFlight = self._flight.bookedFlight
-                # FIXME: translate the ICAO into an airport name
-                fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
-                               "Flight plan closed. Welcome to %s" % \
-                               (bookedFlight.arrivalICAO,),
-                               5)
 
     def prepareFlare(self):
Index: src/mlx/fs.py
===================================================================
--- src/mlx/fs.py	(revision 134)
+++ src/mlx/fs.py	(revision 152)
@@ -64,8 +64,9 @@
         self.daemon = True
 
-    def add(self, messageType, text, duration):
+    def add(self, messageType, text, duration, disconnect):
         """Add the given message to the requested messages."""
         with self._requestCondition:
-            self._messages.append((messageType, text, duration))
+            self._messages.append((messageType, text, duration,
+                                   disconnect))
             self._requestCondition.notify()
 
@@ -80,5 +81,5 @@
         """Perform the thread's operation."""
         while True:
-            (messageType, text, duration) = (None, None, None)
+            (messageType, text, duration, disconnect) = (None, None, None, None)
             with self._requestCondition:
                 now = time.time()
@@ -96,11 +97,12 @@
 
                     if self._messages:
-                        (messageType, text, duration) = self._messages[0]
+                        (messageType, text,
+                         duration, disconnect) = self._messages[0]
                         del self._messages[0]
 
             if text is not None:        
-                self._sendMessage(messageType, text, duration)
-
-    def _sendMessage(self, messageType, text, duration):
+                self._sendMessage(messageType, text, duration, disconnect)
+
+    def _sendMessage(self, messageType, text, duration, disconnect):
         """Send the message and setup the next message time."""
         messageLevel = self._config.getMessageTypeLevel(messageType)
@@ -110,5 +112,12 @@
         if (messageLevel==const.MESSAGELEVEL_FS or \
             messageLevel==const.MESSAGELEVEL_BOTH):
-            self._simulator.sendMessage("[MLX] " + text, duration = duration)
+            if disconnect:
+                self._simulator.disconnect("[MLX] " + text,
+                                           duration = duration)
+            else:
+                self._simulator.sendMessage("[MLX] " + text,
+                                            duration = duration)
+        elif disconnecte:
+            self._simulator.disconnect()
         self._nextMessageTime = time.time() + duration
 
@@ -129,10 +138,10 @@
 #-------------------------------------------------------------------------------
 
-def sendMessage(messageType, text, duration = 3):
+def sendMessage(messageType, text, duration = 3, disconnect = False):
     """Send the given message of the given type into the simulator and/or play
     a corresponding sound."""
     global _messageThread
     if _messageThread is not None:
-        _messageThread.add(messageType, text, duration)
+        _messageThread.add(messageType, text, duration, disconnect)
 
 #-------------------------------------------------------------------------------
Index: src/mlx/fsuipc.py
===================================================================
--- src/mlx/fsuipc.py	(revision 148)
+++ src/mlx/fsuipc.py	(revision 152)
@@ -245,5 +245,7 @@
         """
         with self._requestCondition:
-            self._requests.append(Handler.Request(True, data, callback, extra))
+            request = Handler.Request(True, data, callback, extra)
+            #print "fsuipc.Handler.requestWrite", request
+            self._requests.append(request)
             self._requestCondition.notify()
 
@@ -371,5 +373,6 @@
                 timeout = self._periodicRequests[0].nextFire - time.time()
 
-            if timeout is not None and timeout <= 0.0:
+            if self._requests or \
+               (timeout is not None and timeout <= 0.0):
                 return
             
@@ -378,4 +381,5 @@
     def _disconnect(self):
         """Disconnect from the flight simulator."""
+        print "fsuipc.Handler._disconnect"
         if self._connected:
             pyuipc.close()
@@ -394,4 +398,6 @@
         whole processing the request and reconnecting."""
         self._requestCondition.release()
+
+        #print "fsuipc.Handler._processRequest", request
 
         needReconnect = False
@@ -531,5 +537,5 @@
         self._flareStart = None
         self._flareStartFS = None
-    
+
         self._latin1decoder = codecs.getdecoder("iso-8859-1")
 
@@ -600,5 +606,6 @@
             self._flareRequestID = None
 
-    def sendMessage(self, message, duration = 3):
+    def sendMessage(self, message, duration = 3,
+                    _disconnect = False):
         """Send a message to the pilot via the simulator.
 
@@ -613,5 +620,9 @@
                 (0x32fa, 'h', duration)]
 
-        self._handler.requestWrite(data, self._handleMessageSent)
+        #if _disconnect:
+        #    print "fsuipc.Simulator.sendMessage(disconnect)", message
+
+        self._handler.requestWrite(data, self._handleMessageSent,
+                                   extra = _disconnect)
 
     def getFuel(self, tanks, callback):
@@ -655,10 +666,16 @@
         self._nextSyncTime = -1
             
-    def disconnect(self):
+    def disconnect(self, closingMessage = None, duration = 3):
         """Disconnect from the simulator."""
         assert not self._monitoringRequested 
+
+        print "fsuipc.Simulator.disconnect", closingMessage, duration
         
         self._stopNormal()
-        self._handler.disconnect()
+        if closingMessage is None:
+            self._handler.disconnect()
+        else:
+            self.sendMessage(closingMessage, duration = duration,
+                             _disconnect = True)
 
     def _startDefaultNormal(self):
@@ -874,7 +891,9 @@
         callback(dow, payload, zfw, grossWeight)
 
-    def _handleMessageSent(self, success, extra):
+    def _handleMessageSent(self, success, disconnect):
         """Callback for a message sending request."""
-        pass
+        #print "fsuipc.Simulator._handleMessageSent", disconnect
+        if disconnect:
+            self._handler.disconnect()
 
     def _handleFuelRetrieved(self, data, callback):
Index: src/mlx/gui/gui.py
===================================================================
--- src/mlx/gui/gui.py	(revision 151)
+++ src/mlx/gui/gui.py	(revision 152)
@@ -399,10 +399,15 @@
         self._logView.get_buffer().set_text("")
 
-    def _disconnect(self):
+    def _disconnect(self, closingMessage = None, duration = 3):
         """Disconnect from the simulator if connected."""
         self.stopMonitoring()
 
         if self._connected:
-            self._flight.simulator.disconnect()
+            if closingMessage is None:
+                self._flight.simulator.disconnect()
+            else:
+                fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
+                               closingMessage, duration,
+                               disconnect = True)
             self._connected = False
 
@@ -455,8 +460,8 @@
         self._wizard.setStage(stage)
         if stage==const.STAGE_END:
-            # FIXME: perhaps a more elegant method, e.g.
-            # the simulator should provide a function disconnect
-            # with a final message
-            gobject.timeout_add(1000, self._disconnect)
+            self._disconnect(closingMessage =
+                             "Flight plan closed. Welcome to %s" % \
+                             (self.bookedFlight.arrivalICAO,),
+                             duration = 5)
 
     def setRating(self, rating):
Index: test/test1.txt
===================================================================
--- test/test1.txt	(revision 106)
+++ test/test1.txt	(revision 152)
@@ -1,3 +1,3 @@
-set zfw=45757 hour=7 min=50
+set zfw=44418 hour=7 min=50
 set latitude=47.44 longitude=19.26
 set parking=no
