Problem with subprocess.Popen wget within a thread

Mathieu Prevot mathieu.prevot at gmail.com
Sun Jul 6 20:05:56 CEST 2008


Hi

it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?


(A) ============================================
class vid(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
	def download(self):
		self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
		self.child = subprocess.Popen(self.cmd.split())
	def run(self):
		self.download()

def main():
	w = vid()
	w.start()
	w.join()

(B) ============================================
class vid(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
	def download(self):
		self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
		self.child = subprocess.Popen(self.cmd.split(), stderr=subprocess.PIPE)
	def run(self):
		self.download()
		self.child.stderr.readlines()

def main():
	w = vid()
	w.start()
	w.join()
============================================



More information about the Python-list mailing list