Migration to Python 3

I was able to make quite a bit of progress in my first run of actually trying to update some code. I just stepped in where the compiler failed “direct/ffi/jGenPyCode.py” and ran it from the console alternately using python 3.3 and 2.7, fixing issues as I encountered them to see how far I could get. My first impression is that it is not going to be as difficult as I originally thought, at least on the python side of things. A fairly sizable file like PythonUtil.py (4500 lines) only took about 30 minutes or so before it was working with both python versions (at least its initialization functionality; no syntax, import errors etc.). Also the callable issue is no longer a concern as they’ve re-added it to the language since version 3.2.

There were some things like the re-structuring of the xml and html modules in 3 that required hacks like:

if sys.version_info[0] < 3: from HTMLParser import HTMLParser # Py2
else: from html.parser import HTMLParser  # Py3

but most of it should be fairly clean one line substitutions that work in both versions. The first real problem I encountered was the first time imp.load_dynamic is invoked in “extension_native_helpers.py” to get the libpandaexpress.dll. In 2.7 this obviously works fine but in 3.3 it crashes with:

File "C:\panda3d\direct\extensions_native\extension_native_helpers.py", line 81, in <module>
    Dtool_PreloadDLL("libpandaexpress")
  File "C:\panda3d\direct\extensions_native\extension_native_helpers.py", line 79, in Dtool_PreloadDLL
    imp.load_dynamic(module, pathname)
MemoryError

You mentioned you were able to get at least libpandexpress working in your attempts so I’m assuming this isn’t the crash you were referring to? I watched the memory hit as it ran before it crashed and it didn’t even come close to maxing out my memory so I’m not sure what’s happening here. I checked the 3.3 ref and the “load_dynamic” function is no longer listed in the imp section and a lot of the other functionality is deprecated redirecting the user to importlib, but I couldn’t see anything there that resembled load_dynamic. Either way I should be able to continue working through other branches of the direct tree and start making the syntax changes and such whatever the problem turns out to be here.