JEP and JPype in a single process

Discussion in 'Python' started by skn, Jun 20, 2005.

  1. skn

    skn Guest

    Hello,

    I have written a very simple java class file, which invokes a Python script
    using JEP.

    Code snippet:-
    -------------------
    Jep jep = new Jep(false);
    jep.runScript("C:\\temp\\testscript.py");
    jep.close();

    Now inside this Python script I want to make Java calls using JPype.
    If I use startjvm() inside this Python script, a Runtime Error (exception)
    is thrown.
    Also tried attachThreadToJVM(), but doesn't work, again Runtime Error.

    Any clues as to how I could achieve my goal??
    The interaction shown below should happen in a single process.

    JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA

    Regards,
    skn
     
    skn, Jun 20, 2005
    #1
    1. Advertising

  2. On 6/20/05, skn <> wrote:
    > Hello,
    >
    > I have written a very simple java class file, which invokes a Python script
    > using JEP.

    .. . .
    > Now inside this Python script I want to make Java calls using JPype.


    I am not familiar with either Jepp or JPype, but I spotted this
    snippet on Jepp page (http://jepp.sourceforge.net/):

    import jep
    FileInputStream = jep.findClass('java.io.FileInputStream')
    try:
    fin = FileInputStream('adsf')
    except jep.FileNotFoundException:
    print 'Invalid file'

    Are you sure you need to call JPype?

    - kv
     
    Konstantin Veretennicov, Jun 20, 2005
    #2
    1. Advertising

  3. skn

    Steve Menard Guest

    skn wrote:
    > Hello,
    >
    > I have written a very simple java class file, which invokes a Python script
    > using JEP.
    >
    > Code snippet:-
    > -------------------
    > Jep jep = new Jep(false);
    > jep.runScript("C:\\temp\\testscript.py");
    > jep.close();
    >
    > Now inside this Python script I want to make Java calls using JPype.
    > If I use startjvm() inside this Python script, a Runtime Error (exception)
    > is thrown.
    > Also tried attachThreadToJVM(), but doesn't work, again Runtime Error.
    >
    > Any clues as to how I could achieve my goal??
    > The interaction shown below should happen in a single process.
    >
    > JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA
    >
    > Regards,
    > skn
    >
    >


    You're trying to do something I hope to make possible somewhere down the
    road ...

    As of today, I do not think it is possible. JPype does not provide a way
    to initialize the JVM-bridge system except for startJvm .. which seems
    to be prohibited when a JVM is already running.

    AttachThreadToJVM will only work once the JVM-bridge system has been
    initialize.

    I will look into providing a sister method to startJVM to attach to the
    currently running JVM instead of starting a new one. IF it does not
    require major changes I will release it as 0.5.1. If you'd like you can
    submit an enhancement request on the JPype sourceforge page, so this
    doesn't get lost.



    --
    Steve Menard
    --------------------
    Maintainer of http://jpype.sourceforge.net
     
    Steve Menard, Jun 20, 2005
    #3
  4. skn

    Steve Menard Guest

    Steve Menard wrote:
    > skn wrote:
    >
    >> Hello,
    >>
    >> I have written a very simple java class file, which invokes a Python
    >> script
    >> using JEP.
    >>
    >> Code snippet:-
    >> -------------------
    >> Jep jep = new Jep(false);
    >> jep.runScript("C:\\temp\\testscript.py");
    >> jep.close();
    >>
    >> Now inside this Python script I want to make Java calls using JPype.
    >> If I use startjvm() inside this Python script, a Runtime Error
    >> (exception)
    >> is thrown.
    >> Also tried attachThreadToJVM(), but doesn't work, again Runtime Error.
    >>
    >> Any clues as to how I could achieve my goal??
    >> The interaction shown below should happen in a single process.
    >>
    >> JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA
    >>
    >> Regards,
    >> skn
    >>
    >>

    >
    > You're trying to do something I hope to make possible somewhere down the
    > road ...
    >
    > As of today, I do not think it is possible. JPype does not provide a way
    > to initialize the JVM-bridge system except for startJvm .. which seems
    > to be prohibited when a JVM is already running.
    >
    > AttachThreadToJVM will only work once the JVM-bridge system has been
    > initialize.
    >
    > I will look into providing a sister method to startJVM to attach to the
    > currently running JVM instead of starting a new one. IF it does not
    > require major changes I will release it as 0.5.1. If you'd like you can
    > submit an enhancement request on the JPype sourceforge page, so this
    > doesn't get lost.
    >
    >
    >


    OK .. it now works. There are a few caveats that cannot be resolved
    until either JEP and JPype can somehow cooperate or I finish what I
    started and basically fold the JEP functionality in JPype.

    I will release the new functionality in as version 0.5.1. The "gotchas"
    are going to be in a readme-jep.txt file.

    --
    Steve Menard
    --------------------
    Maintainer of http://jpype.sourceforge.net
     
    Steve Menard, Jun 22, 2005
    #4
  5. skn

    skn Guest

    Thanks for your prompt reply, Steve.
    Just one suggestion, may be the startJVM method's implementation can itself
    be changed to check for already existing JVM.
    Of course this will also mean a change in shutdownJVM() semantics. If JVM
    has been started earlier(not using startJVM()), shutdownJVM() should be a
    do-nothing function.

    Another question I had was, is there any option to suppress the JVM activity
    report that gets displayed. For e.g.,

    JVM activity report :
    classes loaded : 26
    JVM has been shutdown

    I know I can do it by re-directing the std err to NUL.
    But is there any other option?

    With best regards,
    skn

    "Steve Menard" <> wrote in message
    news:MXFte.45766$...
    > skn wrote:
    > > Hello,
    > >
    > > I have written a very simple java class file, which invokes a Python

    script
    > > using JEP.
    > >
    > > Code snippet:-
    > > -------------------
    > > Jep jep = new Jep(false);
    > > jep.runScript("C:\\temp\\testscript.py");
    > > jep.close();
    > >
    > > Now inside this Python script I want to make Java calls using JPype.
    > > If I use startjvm() inside this Python script, a Runtime Error

    (exception)
    > > is thrown.
    > > Also tried attachThreadToJVM(), but doesn't work, again Runtime Error.
    > >
    > > Any clues as to how I could achieve my goal??
    > > The interaction shown below should happen in a single process.
    > >
    > > JAVA ==> jep ==> PYTHON ==> jpype ==> JAVA
    > >
    > > Regards,
    > > skn
    > >
    > >

    >
    > You're trying to do something I hope to make possible somewhere down the
    > road ...
    >
    > As of today, I do not think it is possible. JPype does not provide a way
    > to initialize the JVM-bridge system except for startJvm .. which seems
    > to be prohibited when a JVM is already running.
    >
    > AttachThreadToJVM will only work once the JVM-bridge system has been
    > initialize.
    >
    > I will look into providing a sister method to startJVM to attach to the
    > currently running JVM instead of starting a new one. IF it does not
    > require major changes I will release it as 0.5.1. If you'd like you can
    > submit an enhancement request on the JPype sourceforge page, so this
    > doesn't get lost.
    >
    >
    >
    > --
    > Steve Menard
    > --------------------
    > Maintainer of http://jpype.sourceforge.net
     
    skn, Jun 28, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    9
    Views:
    734
    Neil Benn
    Oct 2, 2004
  2. Wolfgang Keller

    JMS for CPython via JPype?

    Wolfgang Keller, Nov 2, 2004, in forum: Python
    Replies:
    7
    Views:
    1,254
    Steve Menard
    Nov 6, 2004
  3. skn

    Can JEP alone do the job?

    skn, Jul 13, 2005, in forum: Python
    Replies:
    0
    Views:
    314
  4. benchline

    jpype and zxJDBC

    benchline, Apr 8, 2006, in forum: Python
    Replies:
    3
    Views:
    588
    benchline
    Apr 14, 2006
  5. silkenpy

    problem with jpype and thread

    silkenpy, Feb 6, 2008, in forum: Python
    Replies:
    0
    Views:
    710
    silkenpy
    Feb 6, 2008
Loading...

Share This Page