Merge "Found root cause of Monsoon error and fix it" am: ddb83af8cb am: d65ec7f4cc am: 38e98c2932
am: e38fb88d6b

Change-Id: Ic4d28a13ffda1f5369c80a71c4180a421f7676f7
diff --git a/acts/framework/acts/controllers/monsoon.py b/acts/framework/acts/controllers/monsoon.py
index 2ebeccf..160cca7 100644
--- a/acts/framework/acts/controllers/monsoon.py
+++ b/acts/framework/acts/controllers/monsoon.py
@@ -48,7 +48,9 @@
 
 
 def destroy(objs):
-    return
+    for obj in objs:
+        fcntl.flock(obj.mon._tempfile, fcntl.LOCK_UN)
+        obj.mon._tempfile.close()
 
 
 class MonsoonError(acts.signals.ControllerError):
@@ -106,7 +108,7 @@
                     pass
 
                 try:  # use a lockfile to ensure exclusive access
-                    fcntl.lockf(self._tempfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
+                    fcntl.flock(self._tempfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
                 except IOError as e:
                     logging.error("device %s is in use", dev)
                     continue
@@ -988,7 +990,7 @@
 
     def reconnect_monsoon(self):
         """Reconnect Monsoon to serial port.
-        
+
         """
         logging.info("Close serial connection")
         self.mon.ser.close()
@@ -996,8 +998,5 @@
         time.sleep(5)
         logging.info("Open serial connection")
         self.mon.ser.open()
-        self.mon.ser.flush()
         self.mon.ser.reset_input_buffer()
         self.mon.ser.reset_output_buffer()
-        
-        
\ No newline at end of file