JEP and JPype in a single process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • skn

    JEP and JPype in a single process

    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\\tests cript.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 attachThreadToJ VM(), 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


  • Konstantin Veretennicov

    #2
    Re: JEP and JPype in a single process

    On 6/20/05, skn <skn@skn.com> wrote:[color=blue]
    > Hello,
    >
    > I have written a very simple java class file, which invokes a Python script
    > using JEP.[/color]
    .. . .[color=blue]
    > Now inside this Python script I want to make Java calls using JPype.[/color]

    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.FileInp utStream')
    try:
    fin = FileInputStream ('adsf')
    except jep.FileNotFoun dException:
    print 'Invalid file'

    Are you sure you need to call JPype?

    - kv

    Comment

    • Steve Menard

      #3
      Re: JEP and JPype in a single process

      skn wrote:[color=blue]
      > 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\\tests cript.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 attachThreadToJ VM(), 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
      >
      >[/color]

      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.

      AttachThreadToJ VM 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

      Comment

      • Steve Menard

        #4
        Re: JEP and JPype in a single process

        Steve Menard wrote:[color=blue]
        > skn wrote:
        >[color=green]
        >> 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\\tests cript.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 attachThreadToJ VM(), 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
        >>
        >>[/color]
        >
        > 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.
        >
        > AttachThreadToJ VM 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.
        >
        >
        >[/color]

        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

        Comment

        • skn

          #5
          Re: JEP and JPype in a single process

          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" <foo@bar.com> wrote in message
          news:MXFte.4576 6$Fn.345638@web er.videotron.ne t...[color=blue]
          > skn wrote:[color=green]
          > > Hello,
          > >
          > > I have written a very simple java class file, which invokes a Python[/color][/color]
          script[color=blue][color=green]
          > > using JEP.
          > >
          > > Code snippet:-
          > > -------------------
          > > Jep jep = new Jep(false);
          > > jep.runScript(" C:\\temp\\tests cript.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[/color][/color]
          (exception)[color=blue][color=green]
          > > is thrown.
          > > Also tried attachThreadToJ VM(), 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
          > >
          > >[/color]
          >
          > 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.
          >
          > AttachThreadToJ VM 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[/color]


          Comment

          Working...