Py2exe issue

rcmn rcmn73 at gmail.com
Fri Jan 2 11:19:01 EST 2009


I'm using 2.6 (the issue was the same with 2.5)

script.py:

[code]import re

from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f", "--file", action="store", type="string",
dest="filename")
parser.add_option("-o", "--output", action="store", type="string",
dest="fileout")
(options, args) = parser.parse_args()

from subprocess import Popen, PIPE
if options.fileout:
	fileoutput = options.fileout
	output = open(fileoutput, "w")
else:
	output = open("output.txt", "w")
if options.filename:
	rawfile = options.filename
	file = open(rawfile)
else:
	print "type -h for help"
	exit()

from threading import Thread
class Pinger(object):
    def __init__(self, hosts):
        for host in hosts:
            pa = PingAgent(host)
            pa.start()

class PingAgent(Thread):
    def __init__(self, host):
        Thread.__init__(self)
        self.host = host

    def run(self):
        p = Popen('ping -n 1 ' + self.host, stdout=PIPE, stderr=True)
        m = re.search('Average = (.*)ms', p.stdout.read())
        if m:
			output.write (self.host+",pingable\n")
        else:
			output.write (self.host+",not pingable\n")


if __name__ == '__main__':
	pinglist = []
	for line in file:
		pinglist.append(line.strip("\n"))
	Pinger(pinglist)[/code]

py2exe setup.py :

[code]from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
     options = {'py2exe': {'bundle_files': 1}},
     console = [{'script': "script.py"}],
     zipfile = None,
 )
[/code]

error when the "script.exe" run
[code]Exception in thread Thread-500 (most likely raised during
interpreter shutdown):
Traceback (most recent call last):
  File "threading.pyc", line 522, in __bootstrap_inner
  File "script.py", line 35, in run
  File "subprocess.pyc", line 588, in __init__
[/code]

So the script.py run perfectly well under the py environment but if i
use py2exe to make an exe then i get the error above.
I read the note in the py2exe Fac regarding Popen, but i don't know if
it's relevant in my case.



More information about the Python-list mailing list