473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

JEP and JPype in a single process

skn
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
Jul 19 '05 #1
4 2637
On 6/20/05, skn <sk*@skn.com> 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
Jul 19 '05 #2
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
Jul 19 '05 #3
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
Jul 19 '05 #4
skn
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" <fo*@bar.com> wrote in message
news:MX*******************@weber.videotron.net...
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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
14
by: Joachim Boomberschloss | last post by:
Hello, I am working on a project in Python, and I"m currently looking into the possibiliy of writing some of the project"s modules in Java. Given that a large part of the code is already...
3
by: Jim Hargrave | last post by:
I've read that it is possible to compile jython to native code using GCJ. PyLucene uses this approach, they then use SWIG to create a Python wrapper around the natively compiled (java) Lucene. Has...
1
by: benchline | last post by:
I have been trying out jpype for python to java work and love it. It works great on my gentoo box with the java 1.4.2 blackdown sdk. I am now trying it on Red Hat Enterprise Linux 3 for access...
3
by: benchline | last post by:
I would love to be able to use jdbc drivers using the python db 2.0 api and cpython. Has anyone used jpype and zxJDBC (distributed with jython) together? I am trying and what I have tried does...
3
by: kelemen.viktor | last post by:
Hello! Im a quite newbie in the python world. I have some problem with packages, i installed the jpype package according to its intructions. To test ive written: everything worked correctly...
6
by: unlikeablePorpoise | last post by:
I am trying to get JPype to pass a String into a Java class main function. Demonstration code below: =============JAVA============ package com; public class JPypeTest { public static void...
1
by: oyster | last post by:
As you may know, there is no beautiful and free chart(not plot, you can find the examples at http://www.jfree.org/jfreechart, http://www.rmchart.com) module for python than runs on...
1
by: RC | last post by:
Dear Python Experts/Programmers, I'm going to write a Python program to access some Java class methods from our *.jar file. In your opinion, which way is the good (not the best) way to do...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.