ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> py2exe-users
py2exe-users
Re: [Py2exe-users] sys.modules hijinx breaks windows executables
by Thomas Heller other posts by this author
Jul 6 2004 10:01AM messages near this date
[Py2exe-users] PyQt problem | Re: [Py2exe-users] PyQt problem
Jonathan Lange <jml@[...].net>  writes:

>  Hello,
> 
>  A module can attempt to delete itself from sys.modules (see selfabuser.py).
> 
>  This works perfectly well running in the normal python interpreter on
>  many platforms. As evidence, Twisted does this in its reactor module.

Hm.

>  One can build a console exe using py2exe 0.5, where this works perfectly.
> 
>  However, when you build the same script to a windows exe, it fails.
>  Moreover, it fails hard. A try/except block around the offending
>  statement catches nothing.
> 
>  I'd greatly appreciate a work-around. However, I'd appreciate an
>  explanation of why this is failing even more.
> 
>  cheers,
>  jml
>  from distutils.core import setup
>  import py2exe
> 
>  setup(windows=['crash-py2exe.py'])
> 
This is crash-py2exe.py, I assume?
>  f = file('debug.txt', 'w')
>  f.write('Is this the real life?\n')
>  f.close()
> 
>  import selfabuser

And this is selfabuser.py?

>  f = file('debug.txt', 'a')
>  f.write('Is this just fantasy?\n')
>  f.close()
> 
>  import sys
>  del sys.modules['selfabuser']

When I run this in normal Python, I get:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
> >> import selfabuser
Traceback (most recent call last):
  File "<stdin> ", line 1, in ?
ImportError: Loaded module selfabuser not found in sys.modules
> >>

So, it seems a module cannot remove itself from sys.modules - at least
not before the import is completed.

For py2exe, in 0.5.0 there's a bug in windows executables: to make them
work you should add a 'import sys' at the top of your main script.
Or use the CVS version until 0.5.1 is released, the bug is fixed there.

Thomas



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Py2exe-users mailing list
Py2exe-users@[...].net
https://lists.sourceforge.net/lists/listinfo/py2exe-users

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved