[execnet-dev] Issue running code in python2 from a python3 script frozen by cx_Freeze

M T cymrow at gmail.com
Wed Nov 17 02:15:47 CET 2010


I think I've tracked down the problem. It seems execnet points a python
subprocess to the path of the execnet for the main process and tries to get
the subprocess to load that. In a frozen cx_Freeze executable, though, all
the main process' modules are compiled python byte-code, which in my case
would be python3 byte-code, so python2's zipimport can't load it.

Not sure what the best solution to this is. It would be nice if all of the
bootstrap code could be sent through sendexec. For now I will try keeping an
uncompiled copy of execnet with my frozen executable. Any other ideas would
be appreciated, though.

Thanks,
miguel

On Mon, Nov 15, 2010 at 10:48 PM, M T <cymrow at gmail.com> wrote:

> I'm trying to use execnet from a Python 3 script that I've made into an
> executable with cx_Freeze. As a script, the code runs fine, and as an
> executable, when I try to run code with a separate copy of Python 3 it works
> fine. But, as an executable, when I try to run code with a copy of Python 2,
> I get an exception.
>
> It took me a long time to narrow the problem down to this code:
>
> (test.py)
> import execnet
>
>
> def main():
>
> gw = execnet.makegateway('popen//python=c:/dev/Python26/python.exe')   #
> this runs with an exception
>
> # gw = execnet.makegateway('popen//python=c:/dev/Python31/python.exe')  #
> this runs fine
>
> channel = gw.remote_exec('channel.send(1)')
>
> value = channel.receive()   # the exception is raised here
>
> print(value)
>
>
>  if __name__ == '__main__':
>
> main()
>
>
> I am creating the executable with this:
>
> (setup.py)
> from cx_Freeze import setup, Executable
>
>  includes = [
>
> 'execnet.multi', 'execnet.xspec', 'execnet.threadpool',
>
> 'execnet.gateway', 'execnet.gateway_base', 'execnet.gateway_socket',
>
> 'execnet.rsync', 'execnet.rsync_remote']
>
>  setup(
>
> name = "test",
>
> executables = [Executable("test.py")],
>
> options = {
>
>  'build_exe': {
>
>  'includes': includes,
>
>  }
>
>  },
>
>  )
>
>
> Here is the traceback:
>
>
> Traceback (most recent call last):
>
>   File
> "C:\dev\Python31\lib\site-packages\cx_Freeze\initscripts\Console3.py", line
> 27, in <module>
>
>     exec(code, m.__dict__)
>
>   File "test.py", line 11, in <module>
>
>     main()
>
>   File "test.py", line 6, in main
>
>     channel = gw.remote_exec('channel.send(1)')
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway.py",
> line 116, in remote_exec
>
>     (source, call_name, kwargs)))
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway_base.py",
> line 652, in _send
>
>     msg.writeto(self._io)
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway_base.py",
> line 112, in writeto
>
>     serialize(io, (self.msgtype, self.channelid, self.data))
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway_base.py",
> line 939, in serialize
>
>     _Serializer(io).save(obj)
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway_base.py",
> line 959, in save
>
>     self._stream.write(s)
>
>   File
> "C:\dev\Python31\lib\site-packages\execnet-1.0.8-py3.1.egg\execnet\gateway_base.py",
> line 95, in write
>
>     self.outfile.flush()
>
> IOError: [Errno 22] Invalid argument
>
>
> Can someone help me figure out what's going on here?
>
>
> Thanks,
>
> miguel
>
>
> PS: an unrelated issue is the need to explicitly include the execnet
> modules for cx_Freeze, due to the use of apipkg.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/execnet-dev/attachments/20101116/f71386f2/attachment.html>


More information about the execnet-dev mailing list