[execnet-dev] Problem using execnet 1.0.5 with Jython 2.5.1 on WinXP

phatra at gmail.com phatra at gmail.com
Wed Mar 24 13:19:26 CET 2010


Hello Ronny,

Thanks for having a look. I has no idea too. I tried figuring this out  
without success.

 From the traceback, it seem like the problem is with the POpenGateway  
bootstrapping, it expect that 1 byte value 1, but instead it got EOF.

Looking into the _remote_bootstrap_gateway method of the POpenGateway class  
suggests that it tries to import things, test stdout by sending 1, and  
startup exec/eval. This seem fine and work well with different versions of  
cpython (I have 2.4, 2.5, 2.6 to work), however, with Jython, it seem like  
Jython execution of sys.stdout.write('1') statement doesn't reach the  
forker side.

Trying to run similar bootstrap code from console seem to work for both  
cpython and jython.

=================================================================
C:\>echo 'print "hello"' | c:\python26\python.exe -c "import sys;  
sys.stdout.write('1'); sys.stdout.flush(); exec(eval(sys.stdin.readline()))"
1hello

C:\>echo 'print "hello"' | c:\jython2.5.1\jython.bat -c "import sys;  
sys.stdout.write('1'); sys.stdout.flush(); exec(eval(sys.stdin.readline()))"
1hello
=================================================================

I'm still wonder why does it not work inside execnet. My guess is that it  
might be a problem with Jython stdout.


Regards,



Akkratat S.


On Mar 24, 2010 5:13pm, Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>  
wrote:
> hi,



> sadly im left without an idea whats going on,

> maybe holger can help once he's back



> -- Ronny



> On Tue, 2010-03-23 at 08:17 +0700, Akkratat Sintavarattana wrote:

> > Hello Ronny,

> >

> > This is the content of jython.bat file. In the end it execute jython

> > with this command format

> >

> > %_JAVA_CMD% %_JAVA_OPTS% %_JAVA_MEM% %_JAVA_STACK% %_BOOT_CP%

> > -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%

> > CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %_JYTHON_ARGS% %

> > _ARGS%

> >

> > === jython.bat ===

> > ===========================================================

> > @echo off

> > rem This file was generated by the Jython installer

> > rem Created on Thu Feb 04 18:24:05 ICT 2010 by phatra

> >

> > set JAVA_HOME="C:\jdk1.6.0_16"

> > set JYTHON_HOME_FALLBACK="C:\jython2.5.1"

> >

> > @echo off

> > rem

> >  
> ---------------------------------------------------------------------------

> > rem jython.bat - start script for Jython (adapted from jruby.bat)

> > rem

> > rem Environment variables (optional)

> > rem

> > rem JAVA_HOME Java installation directory

> > rem

> > rem JYTHON_HOME Jython installation directory

> > rem

> > rem JYTHON_OPTS Default Jython command line arguments

> > rem

> > rem

> >  
> ---------------------------------------------------------------------------

> >

> > setlocal enabledelayedexpansion

> >

> > rem ----- Verify and set required environment variables

> > -----------------------

> >

> > set _JAVA_CMD=java

> > rem remove surrounding quotes from java home, to be able to safely

> > empty-test it

> > set _TRIMMED_JAVA_HOME=%JAVA_HOME%

> > for /f "useback tokens=*" %%a in ('%_TRIMMED_JAVA_HOME%') do set

> > _TRIMMED_JAVA_HOME=%%~a

> > if not "%_TRIMMED_JAVA_HOME%"=="" (

> > set _JAVA_CMD="%JAVA_HOME:"=%\bin\java"

> > )

> >

> > rem remove surrounding quotes from jython opts, to be able to safely

> > empty-test it

> > set _TRIMMED_JYTHON_OPTS=%JYTHON_OPTS%

> > for /f "useback tokens=*" %%a in ('%_TRIMMED_JYTHON_OPTS%') do set

> > _TRIMMED_JYTHON_OPTS=%%~a

> > if not "%_TRIMMED_JYTHON_OPTS%"=="" (

> > set _JYTHON_OPTS="%_TRIMMED_JYTHON_OPTS%"

> > )

> >

> > rem remove surrounding quotes from jython home, to be able to safely

> > empty-test it

> > set _TRIMMED_JYTHON_HOME=%JYTHON_HOME%

> > for /f "useback tokens=*" %%a in ('%_TRIMMED_JYTHON_HOME%') do set

> > _TRIMMED_JYTHON_HOME=%%~a

> > if not "%_TRIMMED_JYTHON_HOME%"=="" (

> > set _JYTHON_HOME="%_TRIMMED_JYTHON_HOME%"

> > goto gotHome

> > )

> >

> > rem try to dynamically determine jython home

> > rem (this script typically resides in jython home, or in the /bin

> > subdirectory)

> > pushd "%~dp0%"

> > set _JYTHON_HOME="%CD%"

> > popd

> > if exist %_JYTHON_HOME%\jython-dev.jar goto gotHome

> > if exist %_JYTHON_HOME%\jython.jar goto gotHome

> > pushd "%~dp0%\.."

> > set _JYTHON_HOME="%CD%"

> > popd

> > if exist %_JYTHON_HOME%\jython-dev.jar goto gotHome

> > if exist %_JYTHON_HOME%\jython.jar goto gotHome

> > rem jython home fallback (if all else fails)

> > rem if present, %JYTHON_HOME_FALLBACK% is already quoted

> > set _JYTHON_HOME=%JYTHON_HOME_FALLBACK%

> >

> > :gotHome

> > if not exist %_JYTHON_HOME%\jython-dev.jar goto tryComplete

> > rem prefer built version

> > set _CP=%_JYTHON_HOME%\jython-dev.jar

> > for %%j in (%_JYTHON_HOME%\javalib\*.jar) do (

> > set _CP=!_CP!;"%%j"

> > )

> > goto run

> >

> > :tryComplete

> > set _CP=%_JYTHON_HOME%\jython.jar

> > if exist %_JYTHON_HOME%/jython.jar goto run

> >

> > echo Cannot find jython-dev.jar or jython.jar in %_JYTHON_HOME%

> > echo Try running this batch file from the 'bin' directory of an

> > installed Jython,

> > echo or setting JYTHON_HOME.

> > goto cleanup

> >

> > rem ----- Execute the requested command

> > ----------------------------------------

> >

> > :run

> > set _JAVA_MEM=-Xmx512m

> > rem 1152k is the minimum for test_marshal to pass. Windows' default is

> > rem apparently 1M, anyway

> > set _JAVA_STACK=-Xss1152k

> >

> > rem Escape any quotes. Use _S for ', _D for ", and _U to escape _

> > itself.

> > rem We have to escape _ itself, otherwise file names with _S and _D

> > rem will be converted to to wrong ones, when we un-escape. See

> > JRUBY-2821.

> > set _ARGS=%*

> > if not defined _ARGS goto argsDone

> > set _ARGS=%_ARGS:_=_U%

> > set _ARGS=%_ARGS:'=_S%

> > set _ARGS=%_ARGS:"=_D%

> >

> > set _ARGS="%_ARGS%"

> > set _JYTHON_ARGS=

> >

> > :scanArgs

> > rem split args by spaces into first and rest

> > for /f "tokens=1,*" %%i in (%_ARGS%) do call :getArg "%%i" "%%j"

> > goto procArg

> >

> > :getArg

> > rem remove quotes around first arg

> > for %%i in (%1) do set _CMP=%%~i

> > set _ARGS=%2

> > goto :EOF

> >

> > :procArg

> > if ["%_CMP%"] == [""] (

> > set _ARGS=

> > goto argsDone

> > )

> >

> > REM NOTE: If you'd like to use a parameter with underscore in its

> > name,

> > REM NOTE: use the quoted value: --do_stuff -> --do_Ustuff

> >

> > if ["%_CMP%"] == ["--"] goto argsDone

> >

> > if ["%_CMP%"] == ["--jdb"] (

> > if "%_TRIMMED_JAVA_HOME%"=="" (

> > set _JAVA_CMD=jdb

> > ) else (

> > set _JAVA_CMD="%JAVA_HOME:"=%\bin\jdb"

> > )

> > goto :nextArg

> > )

> >

> > if ["%_CMP%"] == ["--boot"] (

> > set _BOOT_CP=-Xbootclasspath/a:%_CP%

> > goto :nextArg

> > )

> >

> > if ["%_CMP%"] == ["--print"] (

> > set _PRINT=print

> > goto :nextArg

> > )

> >

> > rem now unescape _D, _S and _Q

> > set _CMP=%_CMP:_D="%

> > set _CMP=%_CMP:_S='%

> > set _CMP=%_CMP:_U=_%

> > set _CMP1=%_CMP:~0,1%

> > set _CMP2=%_CMP:~0,2%

> >

> > rem detect first character is a quote; skip directly to jythonArg

> > rem this avoids a batch syntax error

> > if "%_CMP1:"=\\%" == "\\" goto jythonArg

> >

> > rem removing quote avoids a batch syntax error

> > if "%_CMP2:"=\\%" == "-J" goto jvmArg

> >

> > :jythonArg

> > set _JYTHON_ARGS=%_JYTHON_ARGS% %_CMP%

> > goto nextArg

> >

> > :jvmArg

> > set _VAL=%_CMP:~2%

> >

> > if "%_VAL:~0,4%" == "-Xmx" (

> > set _JAVA_MEM=%_VAL%

> > ) else if "%_VAL:~0,4%" == "-Xss" (

> > set _JAVA_STACK=%_VAL%

> > ) else (

> > set _JAVA_OPTS=%_JAVA_OPTS% %_VAL%

> > )

> >

> > :nextArg

> > set _CMP=

> > goto scanArgs

> >

> > :argsDone

> > if not defined _BOOT_CP (

> > if defined CLASSPATH (

> > set CLASSPATH=%_CP:"=%;%CLASSPATH:"=%

> > ) else (

> > set CLASSPATH=%_CP:"=%

> > )

> > )

> > set _FULL_CMD=%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_MEM% %_JAVA_STACK% %

> > _BOOT_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0"

> > -classpath "%CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %

> > _JYTHON_ARGS% %_ARGS%

> > if defined _PRINT (

> > echo %_FULL_CMD%

> > ) else (

> > %_FULL_CMD%

> > )

> > set E=%ERRORLEVEL%

> >

> > :cleanup

> > set _ARGS=

> > set _CMP=

> > set _CMP1=

> > set _CMP2=

> > set _CP=

> > set _BOOT_CP=

> > set _FULL_CMD=

> > set _JAVA_CMD=

> > set _JAVA_OPTS=

> > set _JAVA_MEM=

> > set _JAVA_STACK=

> > set _JYTHON_HOME=

> > set _JYTHON_OPTS=

> > set _JYTHON_ARGS=

> > set _PRINT=

> > set _TRIMMED_JAVA_HOME=

> > set _TRIMMED_JYTHON_HOME=

> > set _TRIMMED_JYTHON_OPTS=

> >

> > :finish

> > %COMSPEC% /c exit /b %E%

> >

> > ===========================================================

> >

> >

> > Regards,

> >

> >

> >

> > Akkratat S.

> >

> > On Tue, Mar 23, 2010 at 7:50 AM, Ronny Pfannschmidt

> > Ronny.Pfannschmidt at gmx.de> wrote:

> > On Mon, 2010-03-22 at 17:08 +0700, Akkratat Sintavarattana

> > wrote:

> > > Hello,

> > >

> > > I have problem using execnet 1.0.5 to execute the code

> > within Jython

> > > 2.5.1 on WinXP platform. I wonder whether anyone experience

> > the same

> > > problem. I include the simple test program below with it's

> > output.

> > > Initially, I tried to fixed this myself without success. I

> > thought it

> > > might be the problem with the Jython and not execnet. But

> > since the

> > > documentation states that it's tested with Jython 2.5.1, I

> > guess it

> > > work on platforms other than Windows. Has anyone gotten this

> > to work

> > > Windows?

> > >

> > > If you want me to help test the experimented code or

> > something, I'm

> > > willing to help. This is a very useful and powerful

> > library !

> > >

> > > Thanks for creating this.

> > >

> >

> > the content of jython.bat might be helpfull

> > execnet startup depends on its io setup being correct

> > -- Ronny

> >

> >

> > >

> > > Akkratat S.

> > >

> > >

> > > === Test Code ===

> > > ===========================================================

> > > import execnet

> > >

> > > code = """

> > > import sys

> > > channel.send(sys.version)

> > > """

> > > specs = (

> > > r'popen//python=c:\python25\python.exe',

> > > r'popen//python=c:\python26\python.exe',

> > > r'popen//python=jython.bat',

> > > )

> > > # my jython is in c:\jython2.5.1, which is set in PATH

> > >

> > > for spec in specs:

> > > gw = execnet.makegateway(spec)

> > > ch = gw.remote_exec(code)

> > > print ch.receive()

> > > print '-' * 70

> > > ===========================================================

> > >

> > > === Output ===

> > > ===========================================================

> > > C:\temp>c:\python26\python.exe test_remote.py

> > > 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit

> > (Intel)]

> > >

> > ----------------------------------------------------------------------

> > > 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit

> > (Intel)]

> > >

> > ----------------------------------------------------------------------

> > > Traceback (most recent call last):

> > > File "test_remote.py", line 14, in

> > > gw = execnet.makegateway(spec)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \multi.py", line 77, in makegateway

> > > gw = gateway.PopenGateway(python=spec.python, id=id)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \gateway.py", line 157, in __init__

> > > super(PopenGateway, self).__init__(args, id=id)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \gateway.py", line 139, in __init__

> > > super(PopenCmdGateway, self).__init__(io=io, id=id)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \gateway.py", line 18, in __init__

> > > self._remote_bootstrap_gateway(io)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \gateway.py", line 170, in _remote_bootstrap_gateway

> > > s = io.read(1)

> > > File "c:\python26\lib\site-packages

> > \execnet-1.0.5-py2.6.egg\execnet

> > > \gateway_base.py", line 86, in read

> > > raise EOFError("expected %d bytes, got %d" %(numbytes,

> > len(buf)))

> > > EOFError: expected 1 bytes, got 0

> > > ===========================================================

> >

> > > _______________________________________________

> > > execnet-dev mailing list

> > > execnet-dev at codespeak.net

> > > http://codespeak.net/mailman/listinfo/execnet-dev

> >

> >



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/execnet-dev/attachments/20100324/a91a7ce5/attachment.html>


More information about the execnet-dev mailing list