[gvfs] gvfs-test: Avoid deadlocks when waiting for CLI user prompts



commit 5c1843f5905255cbb471fe414a66eeee78102662
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed May 29 12:36:31 2013 +0200

    gvfs-test: Avoid deadlocks when waiting for CLI user prompts
    
    Force subprocess' stdout to be non-blocking, so that we do not potentially wait
    forever, but time out properly.

 test/gvfs-test |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/test/gvfs-test b/test/gvfs-test
index e8b1416..00b846a 100755
--- a/test/gvfs-test
+++ b/test/gvfs-test
@@ -174,6 +174,10 @@ class GvfsTestCase(unittest.TestCase):
         '''Wait for a gvfs-mount Popen process to show an User auth prompt'''
 
         empty_timeout = 50
+
+        # set stdout to nonblocking
+        flags = fcntl.fcntl(popen.stdout, fcntl.F_GETFL)
+        fcntl.fcntl(popen.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
         while True:
             r = popen.stdout.read(1000)
             #print('  wait_for_gvfs_mount_user_prompt: got "%s"' % str(r))
@@ -185,6 +189,9 @@ class GvfsTestCase(unittest.TestCase):
             empty_timeout -= 1
             time.sleep(0.1)
 
+        # restore flags
+        fcntl.fcntl(popen.stdout, fcntl.F_SETFL, flags)
+
     def mount_api(self, gfile, mount_op=None):
         '''Mount a Gio.File using the Gio API
         


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]