Java <-> Python localhost stream, Java does not continue -
problem summary
i've got application combines both java , python, 2 languages communicating across localhost socket. (i cannot use jython, can't throw out java pygame, , can't throw out python pure java.)
the application opens socket between python , java , socket java central server. input java ui or server passed on python, program logic taken care of. python sends messages java either passed on server, or interpreted use on client (eg, python tells java draw screen).
code snippets
client.java:main
pyconnect python = new pyconnect(); thread th = new thread(python); th.start(); while(!python.isinitialized()); client game = new client(); pythonmessagedecoder.setgame(game); th = new thread(game); th.start();
pyconnect.java:run
system.out.println("starting..."); // ...initialize serversocket instance python... try { // ...accept connection python... system.out.println("connected!!!"); } // ...catch... try { // ...get input/output streams... system.out.println("both streams up"); } // ...catch... initialized = true; while(pythonmessagedecoder.getinstance() == null); // ...read python...
pythonmessagedecoder.java
public static void setgame(game game) { pythonmessagedecoder.game = game; } public static pythonmessagedecoder getinstance() { if(game == null) return null; return instanceholder.instance; } // ...
problem detail
on of our windows machines (xp, vista, , w7; x86 , x64), process runs fine. on our ubuntu , osx machines, there no exceptions (in either python or java)... no java frame appears. in samples above, i've left in trace debugging, , mac , linux boxes print:
starting...
connected!!!
both streams up
additionally, other java portions of our project (which don't try combine python) work fine. python shell works fine. python code runs fine (if python didn't connect, pyconnect
not reach 'connected!!!' line).
solution attempts
at first, thought issue might have been deadlock between 2 threads, both stop wait condition before completing task. pyconnect
sets initialized
state before waiting, , main thread checking pyconnect
has reached initialized
state. honest, i'm not issue is.
Comments
Post a Comment