Py2exe issue

R

rcmn

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)

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,
 )

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__

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.
 
M

Mike Driscoll

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)

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,
 )

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__

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.

Try it with bundle_files option 3 instead of 1. Also what version of
py2exe are you using?

Mike
 
R

rcmn

I'm using py2exe-0.6.9.win32-py2.6.exe

i used option 3.
On a list of 500 i get the same error than previous.
On a list of 250 once it just quit leaving the open file at 0k and on
the second attempt it failed with the same error and a note about
"TypeError: 'NoneType' object is not callable".
Basically totally random errors.
Obviously there is something that py2exe cannot bundle. because I have
been using this script(as *.py) more than 30 times now .And as long as
i respect the 500 window$ limitation. I had no issues.
 
R

rcmn

I just tried to compile with gui2exe. And i ran the exe. it faile the
same way but at least generate a log.
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.pyc", line 522, in __bootstrap_inner
File "pingable.py", line 35, in run
File "subprocess.pyc", line 588, in __init__
File "subprocess.pyc", line 707, in _get_handles
File "subprocess.pyc", line 752, in _make_inheritable
WindowsError: [Error 6] The handle is invalid

for every entry it generate this error and the line 35 is ...Popen !
 
R

rcmn

I just tried to compile with gui2exe. And i ran the exe. it faile the
same way but at least generate a log.
Exception in thread Thread-1:
Traceback (most recent call last):
  File "threading.pyc", line 522, in __bootstrap_inner
  File "pingable.py", line 35, in run
  File "subprocess.pyc", line 588, in __init__
  File "subprocess.pyc", line 707, in _get_handles
  File "subprocess.pyc", line 752, in _make_inheritable
WindowsError: [Error 6] The handle is invalid

for every entry it generate this error and the line 35 is ...Popen !

alright here is the issue :
http://www.py2exe.org/index.cgi/Py2ExeSubprocessInteractions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top