From bd6971d36c3f47da281996eb2f67466a10aa7860 Mon Sep 17 00:00:00 2001
From: Marcus Comstedt <marcus@mc.pp.se>
Date: Tue, 2 Nov 2010 19:59:16 +0100
Subject: [PATCH] Improved performance of Process.run when threads aren't
 supported.

Patch taken from githelper: Instead of calling Pike.DefaultBackend() until
p->status() says that the process has terminated, loop until both stdout and
stderr have been closed. This is better because otherwise we may be stuck
inside the backend for up to one second while the process is already
terminated. This change gives a considerable speedup on Solaris.
---
 lib/modules/Process.pmod | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lib/modules/Process.pmod b/lib/modules/Process.pmod
index 3d36553873..d6d90350f6 100644
--- a/lib/modules/Process.pmod
+++ b/lib/modules/Process.pmod
@@ -236,23 +236,27 @@ mapping run(string|array(string) cmd, void|mapping modifiers)
   mystderr->set_read_callback( lambda( mixed i, string data) {
                                  gotstderr += data;
                                } );
+  mystdout->set_close_callback( lambda () {
+				  mystdout->set_read_callback(0);
+				  mystdout = 0;
+				});
+  mystderr->set_close_callback( lambda () {
+				  mystderr->set_read_callback(0);
+				  mystderr = 0;
+				});
 
   if (mystdin) {
     Shuffler.Shuffle sf = Shuffler.Shuffler()->shuffle( mystdin );
     sf->add_source(stdin_str);
+    sf->set_done_callback (lambda () {
+			     mystdin = 0;
+			   });
     sf->start();
-    mystdin = 0;
   }
 
-  while( !p->status() || p->status() == 1 )
+  while( mystdout || mystderr || mystdin )
     Pike.DefaultBackend( 1.0 );
 
-  mystdout->set_read_callback(0);
-  mystderr->set_read_callback(0);
-  
-  gotstdout += mystdout->read();
-  gotstderr += mystderr->read();
-
   exitcode = p->wait();
 #endif
 
-- 
GitLab