Browse Source

Replace the usage of the deprecated popen2.Popen3() with subprocess.Popen().

Emmanuel Bouthenot 13 years ago
parent
commit
e285e16055
2 changed files with 22 additions and 15 deletions
  1. 11 4
      CHANGELOG
  2. 11 11
      pmailq

+ 11 - 4
CHANGELOG

@@ -3,10 +3,17 @@ pmailq - Postfix MAIL Queue manager
 
 ChangeLog
 
+Version 0.4 (2010-12-29):
+    * Replace the usage of the deprecated popen2.Popen3() with
+      subprocess.Popen().
+
+Version 0.3 (2010-01-31):
+    * Fix dead lock while processing a large amount of datas in mail queue
+
 Version 0.2 (2008-01-08):
-  * Add Changelog
-  * Fix typos in manpage
-  * Fix exit code on errors (http://bugs.debian.org/457299)
+    * Add Changelog
+    * Fix typos in manpage
+    * Fix exit code on errors (http://bugs.debian.org/457299)
 
 Version 0.1 (2007-11-27):
-  * first release
+    * First release

+ 11 - 11
pmailq

@@ -20,28 +20,28 @@ DELQ = "postsuper -d"
 
 
 from optparse import OptionParser, OptionGroup # needs python >= 2.3
-import sys, os, popen2, fcntl, select, fnmatch
+import sys, os, subprocess, fcntl, select, fnmatch
 
 class Proc:
-    
+
     def run(self, command):
-        child = popen2.Popen3(command, 1)
-        child.tochild.close()             
-        outfile = child.fromchild
+        proc = subprocess.Popen(command, bufsize=1, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
+        proc.stdin.close()
+        outfile = proc.stdout
         outfd = outfile.fileno()
-        errfile = child.childerr
+        errfile = proc.stderr
         errfd = errfile.fileno()
 
         # avoid deadlocks
         self.set_no_block(outfd)
         self.set_no_block(errfd)
-        
+
         outdata = errdata = ''
         outeof = erreof = False
 
         while True:
             # wait for activity
-            ready = select.select([outfd,errfd],[],[])
+            ready = select.select([outfd, errfd], [], [])
             if outfd in ready[0]:
                 outchunk = outfile.read()
                 if outchunk == '':
@@ -56,9 +56,9 @@ class Proc:
                 break
             # give a little time for buffers to fill
             select.select([],[],[],.1)
-        
-        err = child.wait()
-        
+
+        err = proc.wait()
+
         return err, outdata, errdata
 
     def set_no_block(self, fd):