From: John Goerzen Date: Wed, 14 Mar 2007 01:54:19 +0000 (+0100) Subject: Don't leave preauthtunnel zombies with autorefresh X-Git-Tag: Working_post-imaplib_removal~21 X-Git-Url: https://code.delx.au/offlineimap/commitdiff_plain/79a596be7b98801d71b0ac8d120384606274ce42 Don't leave preauthtunnel zombies with autorefresh From: Peter Colberg Hello, using offlineimap with the preauthtunnel option to start a remote IMAP daemon via ssh, a zombie process is left behind during the autorefresh sleep period if not holding the connection open. Above behaviour is a result of using os.popen2 to spawn the tunnel process, which makes it impossible waiting for the child process to terminate when shutting down the tunnel. The patch included below fixes the issue by employing the Popen class from the subprocess module, which seems to be the preferred way to spawn processes and connect to their pipes in any case (at least since python version 2.4.4, which fixes a memory leak in the subprocess module). Regards, Peter fixes deb#410730 --- diff --git a/offlineimap/imaplib.py b/offlineimap/imaplib.py index a4bdc22..d70819e 100644 --- a/offlineimap/imaplib.py +++ b/offlineimap/imaplib.py @@ -22,7 +22,7 @@ Public functions: Internaldate2tuple __version__ = "2.52" -import binascii, re, socket, time, random, sys, os +import binascii, re, socket, time, random, subprocess, sys, os from offlineimap.ui import UIBase __all__ = ["IMAP4", "Internaldate2tuple", "Internaldate2epoch", @@ -1049,7 +1049,9 @@ class IMAP4_Tunnel(IMAP4): def open(self, host, port): """The tunnelcmd comes in on host!""" - self.outfd, self.infd = os.popen2(host, "t", 0) + self.process = subprocess.Popen(host, shell=True, close_fds=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + (self.outfd, self.infd) = (self.process.stdin, self.process.stdout) def read(self, size): retval = '' @@ -1066,6 +1068,7 @@ class IMAP4_Tunnel(IMAP4): def shutdown(self): self.infd.close() self.outfd.close() + self.process.wait() class sslwrapper: