py4j-users Mailing List for Py4J (Page 6)
Status: Beta
Brought to you by:
barthe
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
|
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
2011 |
Jan
(6) |
Feb
(1) |
Mar
(8) |
Apr
(6) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
|
Dec
(4) |
2012 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(7) |
Jun
(9) |
Jul
(10) |
Aug
|
Sep
|
Oct
(6) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
(1) |
2014 |
Jan
(3) |
Feb
|
Mar
(3) |
Apr
|
May
(5) |
Jun
|
Jul
(2) |
Aug
(3) |
Sep
|
Oct
(1) |
Nov
|
Dec
(21) |
2015 |
Jan
(2) |
Feb
(5) |
Mar
(4) |
Apr
|
May
|
Jun
(5) |
Jul
(12) |
Aug
|
Sep
(1) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
From: Barthelemy D. <ba...@cs...> - 2011-04-19 09:55:42
|
Hi Sean, The way Py4J works is that python code is executed in a Python interpreter and Java code is invoked by a Java Virtual Machine. Both the Python interpreter and the JVM must be started prior to using Py4J. In other words, Py4J won't start a JVM to execute code in a jar file. To run the example, first, locate the py4j.jar and your jar and execute this command (using the right path): java -cp path\to\py4j.jar;path\to\yourlib.jar \ py4j.examples.AdditionApplication Then, open a python interpreter and try the example code, it should work. You should also be able to access the code in your jar file. Hope this helps, Barthélémy On 04/18/2011 08:43 PM, Sean Silvestri wrote: > Hi Barthelemy, > Interesting, I did not start any Java program. I must have > misunderstood the premise of the module. > My main goal is to simply call into a java jar file that I've > registered e.g. the classpath. > > Since that was not working I just resorted to the basic sample on the > web site using the .java.util.Random class (see below) > I'm simply wanting to interface with a jar file in order to call the > java methods. > gateway = JavaGateway() # connect to the JVM >>>> random = gateway.jvm.java.util.Random() # create a java.util.Random instance >>>> number1 = random.nextInt(10) # call the Random.nextInt method >>>> number2 = random.nextInt(10) >>>> print(number1,number2) > (2, 7) > > I had also turned off my firewall but still had gotten the error i had > mentiond ( [Errno 10061] No connection could be made because the > target machine actively refused it). > > What would be the steps to be able to call java code situated in a > .jar file from a python script using py4j? > many thanks, > Sean > > > > On Mon, Apr 18, 2011 at 5:21 PM, Barthelemy Dagenais<ba...@cs...> wrote: >> Hi Sean, >> >> this error means that the python interpreter cannot connect to the jvm >> either because: >> >> 1- The jvm is not yet started so nothing is listening on the default py4j >> port. >> >> 2- You have a firewall blocking the port. >> >> You need to start the java program in the example and then, you can start >> your python interpreter (not the other way around). >> >> If you don't have a firewall and if you started the Java program before >> running the interpreter, we will need more information to help you (e.g., >> how did you start the Java program, what is the output of the "netstat" >> command in a command prompt after starting the Java program, etc.). >> >> Barthélémy >> >> On Mon, April 18, 2011 8:07 pm, Sean Silvestri wrote: >>> HI All, >>> I'm just getting started with Py4J, basically just trying to call a >>> jar. I'm having trouble with the basic sample however: >>> >>> >>>>>> from py4j.java_gateway import JavaGateway gateway = JavaGateway() >>>>>> # connect to the JVM >>>>>> random = gateway.jvm.java.util.Random() # create a >>>>>> java.util.Random instance number1 = random.nextInt(10) >>>>>> # call the Random.nextInt method >>>>>> number2 = random.nextInt(10) print(number1,number2) >>> (2, 7) >>> >>>>>> addition_app = gateway.entry_point # get the >>>>>> AdditionApplication instance >>>>>> addition_app.addition(number1,number2) # call the addition method >>>>>> >>> 9 >>> >>> >>> I keep getting the following error: [Errno 10061] No connection could >>> be made because the target machine actively refused it >>> >>> I'm on python 2.71 for windows i have jre6 se installed have set path. >>> cheers, Sean >>> >>> >>> ------------------------------------------------------------------------- >>> ----- >>> Benefiting from Server Virtualization: Beyond Initial Workload >>> Consolidation -- Increasing the use of server virtualization is a top >>> priority.Virtualization can reduce costs, simplify management, and improve >>> application availability and disaster protection. Learn more about >>> boosting the value of server virtualization. >>> http://p.sf.net/sfu/vmware-sfdev2dev >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users >>> >>> >> >> >> |
From: Barthelemy D. <ba...@cs...> - 2011-04-19 00:21:45
|
Hi Sean, this error means that the python interpreter cannot connect to the jvm either because: 1- The jvm is not yet started so nothing is listening on the default py4j port. 2- You have a firewall blocking the port. You need to start the java program in the example and then, you can start your python interpreter (not the other way around). If you don't have a firewall and if you started the Java program before running the interpreter, we will need more information to help you (e.g., how did you start the Java program, what is the output of the "netstat" command in a command prompt after starting the Java program, etc.). Barthélémy On Mon, April 18, 2011 8:07 pm, Sean Silvestri wrote: > HI All, > I'm just getting started with Py4J, basically just trying to call a > jar. I'm having trouble with the basic sample however: > > >>>> from py4j.java_gateway import JavaGateway gateway = JavaGateway() >>>> # connect to the JVM >>>> random = gateway.jvm.java.util.Random() # create a >>>> java.util.Random instance number1 = random.nextInt(10) >>>> # call the Random.nextInt method >>>> number2 = random.nextInt(10) print(number1,number2) > (2, 7) > >>>> addition_app = gateway.entry_point # get the >>>> AdditionApplication instance >>>> addition_app.addition(number1,number2) # call the addition method >>>> > 9 > > > I keep getting the following error: [Errno 10061] No connection could > be made because the target machine actively refused it > > I'm on python 2.71 for windows i have jre6 se installed have set path. > cheers, Sean > > > ------------------------------------------------------------------------- > ----- > Benefiting from Server Virtualization: Beyond Initial Workload > Consolidation -- Increasing the use of server virtualization is a top > priority.Virtualization can reduce costs, simplify management, and improve > application availability and disaster protection. Learn more about > boosting the value of server virtualization. > http://p.sf.net/sfu/vmware-sfdev2dev > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > > |
From: Sean S. <sea...@gm...> - 2011-04-19 00:07:21
|
HI All, I'm just getting started with Py4J, basically just trying to call a jar. I'm having trouble with the basic sample however: >>> from py4j.java_gateway import JavaGateway >>> gateway = JavaGateway() # connect to the JVM >>> random = gateway.jvm.java.util.Random() # create a java.util.Random instance >>> number1 = random.nextInt(10) # call the Random.nextInt method >>> number2 = random.nextInt(10) >>> print(number1,number2) (2, 7) >>> addition_app = gateway.entry_point # get the AdditionApplication instance >>> addition_app.addition(number1,number2) # call the addition method 9 I keep getting the following error: [Errno 10061] No connection could be made because the target machine actively refused it I'm on python 2.71 for windows i have jre6 se installed have set path. cheers, Sean |
From: Barthelemy D. <ba...@cs...> - 2011-04-14 18:39:27
|
Hi Mike, Yes, you can do this with Py4J. I actually used it in a similar fashion with Eclipse. I was tired to restart Eclipse every time I made a change to a plug-in so I just installed Py4J in Eclipse and then, I accessed Eclipse using a Python shell. After experimenting for a while with the shell, I copied the code to a Python program (or translated it to Java when it made sense). With Py4J, you can also write a Python class that implements a Java interface and you can pass it to the JVM. This allows a Python program (or a Python shell), to receive a callback from Java, which seems to fit your scenario here. The only thing you cannot do right now is extend a Java abstract class in Python (it's on my todo list). Py4J also supports many-to-many connections between Python interpreters and JVMs: you can safely connect multiple python interpreters on the same JVM, restart an interpreter and reconnect to the same JVM, etc. Another handy tool from Py4J is that you can use introspection on Java objects. This might be helpful if you don't know the types in your agent's state. For example, in Eclipse, you often get Object instances that you need to cast. With Py4J, you can call a method on the object and you will get its type and the methods and fields that are accessible. Hope this helps, Barthélémy On Thu, April 14, 2011 2:05 pm, Bourassa, Mike wrote: > Hi there. I'm Mike Bourassa. I have a question about whether P4J has a > functionality I'm seeking. > > > > I have been working with Netlogo (http://ccl.northwestern.edu/netlogo/), > an agent development environment. While it is a very nice system, I have > reached a stage where I would like to do some more exotic agent behaviour. > While Netlogo is easy to program in, I need to use more > complex algorithms that exist in libraries for Java, Python, etc. Netlogo > allows me to write extensions; essentially I write a program, create a > .jar, and Netlogo can call the contents of the .jar. > > > > > In my current set-up, each agent in Netlogo at some point calls the > extension .jar. The .jar contains methods that provide decision making for > the agents; state data goes in, a decision comes out. The problem is > every time I change the decision making algorithm I have to: shut down > Netlogo, alter program, create .jar, restart Netlogo. So I > thought, what if the extension just holds the state data and returns a > decision, while I use a Python program to do the decision making. That > is, the .jar extension would hold the state data and using P4J, a Python > program would access the data and return a decision which the extension > would then pass back to Netlogo. The advantage would be that I could > alter the Python program without having to recreate a .jar and shutdown > Netlogo every time. > > > > > So: does that make any sense and could P4J help me achieve my goal? > Thanks in advance for any assistance. > > > > > Mike Bourassa > > > > > - > > > > > |
From: Bourassa, M. <Mik...@dr...> - 2011-04-14 18:21:15
|
Hi there. I'm Mike Bourassa. I have a question about whether P4J has a functionality I'm seeking. I have been working with Netlogo (http://ccl.northwestern.edu/netlogo/), an agent development environment. While it is a very nice system, I have reached a stage where I would like to do some more exotic agent behaviour. While Netlogo is easy to program in, I need to use more complex algorithms that exist in libraries for Java, Python, etc. Netlogo allows me to write extensions; essentially I write a program, create a .jar, and Netlogo can call the contents of the .jar. In my current set-up, each agent in Netlogo at some point calls the extension .jar. The .jar contains methods that provide decision making for the agents; state data goes in, a decision comes out. The problem is every time I change the decision making algorithm I have to: shut down Netlogo, alter program, create .jar, restart Netlogo. So I thought, what if the extension just holds the state data and returns a decision, while I use a Python program to do the decision making. That is, the .jar extension would hold the state data and using P4J, a Python program would access the data and return a decision which the extension would then pass back to Netlogo. The advantage would be that I could alter the Python program without having to recreate a .jar and shutdown Netlogo every time. So: does that make any sense and could P4J help me achieve my goal? Thanks in advance for any assistance. Mike Bourassa - |
From: Alec C. <ar...@fa...> - 2011-03-16 21:53:33
|
Hi Barthélémy, Thanks for the fix! It's working great now. Alec Quoting Barthelemy Dagenais <ba...@cs...>: > Hi Alec, > > Thanks for reporting this bug and for the test case, it was very helpful! > > I just pushed a fix to the git repository and I added your test case in > the unit test suite. > > Don't hesitate to post again if you find another bug! > > Barthélémy > > On 03/16/2011 02:20 PM, Alec Chapman wrote: > > Hi, > > I've just started trying out py4j and am finding it really helpful so far. > I > > was able to implement a simple Java interface in Python, but I'm running > into > > trouble with more complicated interfaces. > > > > Specifically, I'm having trouble when one interface has a function that > returns > > another interface, with both interfaces implemented in Python. The problem > > seems to be that the python object is only treated as a Java interface when > it > > is passed as an argument, not when it is the return value. > > > > I've included a simple example below. Is what I'm trying to do possible? > > Thanks for any help, > > Alec > > > > Here's the python code: > > -------------------------------------------------- > > > > from py4j.java_gateway import JavaGateway > > > > class A(object): > > class Java: > > implements = ['py4j.examples.InterfaceA'] > > > > class B(object): > > def foo(self): > > return A() #this doesn't work > > return gateway.jvm.py4j.examples.ClassA() #this does > > class Java: > > implements = ['py4j.examples.InterfaceB'] > > > > gateway = JavaGateway(start_callback_server=True) > > gateway.entry_point.test(B()) > > > > And here's the Java code: > > -------------------------------------------- > > > > public interface InterfaceA { > > } > > > > public interface InterfaceB { > > public InterfaceA foo(); > > } > > > > public class ClassA implements InterfaceA{ > > } > > > > public class InterfaceExample { > > > > public void test(InterfaceB b) { > > InterfaceA a = b.foo(); > > } > > > > public static void main(String[] args) { > > GatewayServer server = new GatewayServer(new InterfaceExample()); > > server.start(); > > } > > } > > > > ------------------------------------- > > The error occurs in the line 'return A()': > > > > py4j.protocol.Py4JJavaError: An error occurred while calling t.test. > > : py4j.Py4JException: An exception was raised by the Python Proxy. > > at py4j.Protocol.getReturnValue(Protocol.java:393) > > at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:100) > > at $Proxy0.foo(Unknown Source) > > at py4j.examples.InterfaceExample.test(InterfaceExample.java:8) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > > at > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > > at java.lang.reflect.Method.invoke(Method.java:597) > > at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:119) > > at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:392) > > at py4j.Gateway.invoke(Gateway.java:255) > > at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:124) > > at py4j.commands.CallCommand.execute(CallCommand.java:81) > > at py4j.GatewayConnection.run(GatewayConnection.java:175) > > at java.lang.Thread.run(Thread.java:662) > > > > > > > > > ------------------------------------------------------------------------------ > > Colocation vs. Managed Hosting > > A question and answer guide to determining the best fit > > for your organization - today and in the future. > > http://p.sf.net/sfu/internap-sfd2d > > _______________________________________________ > > Py4j-users mailing list > > Py4...@li... > > https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Barthelemy D. <ba...@cs...> - 2011-03-16 19:27:27
|
Hi Alec, Thanks for reporting this bug and for the test case, it was very helpful! I just pushed a fix to the git repository and I added your test case in the unit test suite. Don't hesitate to post again if you find another bug! Barthélémy On 03/16/2011 02:20 PM, Alec Chapman wrote: > Hi, > I've just started trying out py4j and am finding it really helpful so far. I > was able to implement a simple Java interface in Python, but I'm running into > trouble with more complicated interfaces. > > Specifically, I'm having trouble when one interface has a function that returns > another interface, with both interfaces implemented in Python. The problem > seems to be that the python object is only treated as a Java interface when it > is passed as an argument, not when it is the return value. > > I've included a simple example below. Is what I'm trying to do possible? > Thanks for any help, > Alec > > Here's the python code: > -------------------------------------------------- > > from py4j.java_gateway import JavaGateway > > class A(object): > class Java: > implements = ['py4j.examples.InterfaceA'] > > class B(object): > def foo(self): > return A() #this doesn't work > return gateway.jvm.py4j.examples.ClassA() #this does > class Java: > implements = ['py4j.examples.InterfaceB'] > > gateway = JavaGateway(start_callback_server=True) > gateway.entry_point.test(B()) > > And here's the Java code: > -------------------------------------------- > > public interface InterfaceA { > } > > public interface InterfaceB { > public InterfaceA foo(); > } > > public class ClassA implements InterfaceA{ > } > > public class InterfaceExample { > > public void test(InterfaceB b) { > InterfaceA a = b.foo(); > } > > public static void main(String[] args) { > GatewayServer server = new GatewayServer(new InterfaceExample()); > server.start(); > } > } > > ------------------------------------- > The error occurs in the line 'return A()': > > py4j.protocol.Py4JJavaError: An error occurred while calling t.test. > : py4j.Py4JException: An exception was raised by the Python Proxy. > at py4j.Protocol.getReturnValue(Protocol.java:393) > at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:100) > at $Proxy0.foo(Unknown Source) > at py4j.examples.InterfaceExample.test(InterfaceExample.java:8) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:119) > at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:392) > at py4j.Gateway.invoke(Gateway.java:255) > at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:124) > at py4j.commands.CallCommand.execute(CallCommand.java:81) > at py4j.GatewayConnection.run(GatewayConnection.java:175) > at java.lang.Thread.run(Thread.java:662) > > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Alec C. <ar...@fa...> - 2011-03-16 18:36:45
|
Hi, I've just started trying out py4j and am finding it really helpful so far. I was able to implement a simple Java interface in Python, but I'm running into trouble with more complicated interfaces. Specifically, I'm having trouble when one interface has a function that returns another interface, with both interfaces implemented in Python. The problem seems to be that the python object is only treated as a Java interface when it is passed as an argument, not when it is the return value. I've included a simple example below. Is what I'm trying to do possible? Thanks for any help, Alec Here's the python code: -------------------------------------------------- from py4j.java_gateway import JavaGateway class A(object): class Java: implements = ['py4j.examples.InterfaceA'] class B(object): def foo(self): return A() #this doesn't work return gateway.jvm.py4j.examples.ClassA() #this does class Java: implements = ['py4j.examples.InterfaceB'] gateway = JavaGateway(start_callback_server=True) gateway.entry_point.test(B()) And here's the Java code: -------------------------------------------- public interface InterfaceA { } public interface InterfaceB { public InterfaceA foo(); } public class ClassA implements InterfaceA{ } public class InterfaceExample { public void test(InterfaceB b) { InterfaceA a = b.foo(); } public static void main(String[] args) { GatewayServer server = new GatewayServer(new InterfaceExample()); server.start(); } } ------------------------------------- The error occurs in the line 'return A()': py4j.protocol.Py4JJavaError: An error occurred while calling t.test. : py4j.Py4JException: An exception was raised by the Python Proxy. at py4j.Protocol.getReturnValue(Protocol.java:393) at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:100) at $Proxy0.foo(Unknown Source) at py4j.examples.InterfaceExample.test(InterfaceExample.java:8) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:119) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:392) at py4j.Gateway.invoke(Gateway.java:255) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:124) at py4j.commands.CallCommand.execute(CallCommand.java:81) at py4j.GatewayConnection.run(GatewayConnection.java:175) at java.lang.Thread.run(Thread.java:662) |
From: Barthelemy D. <ba...@cs...> - 2011-03-16 12:26:38
|
Hi, I'm afraid you won't be able to use Py4J for that. The Python side only keeps a reference to objects on the Java side (like an OID). The actual members or even the class definition is not stored on the Python side. In other words, objects are passed by reference, not by value. I believe RMI might be more suited because it serializes the objects but you need to implement the Remote interface (if I remember correctly). If you still want to use Python and Py4J, another alternative would be to serialize the object and just send the byte[] to the Python side. You could have something like: public interface StoreRestore1 { void store(String id, byte[] object); byte[] restore(String id); } or public interface StoreRestore2 { void store(String id, Serializable object); Serializable restore(String id); } In StoreRestore1, the Java side is responsible for serializing the object first before sending it to the Python object implementing the interface. In StoreRestore2, the Python object implementing the interface is responsible for serializing the object (probably by using the ObjectOutputStream/ObjectInputStream, ByteArrayOutputStream/ByteArrayInputStream). If you go with either of these solutions, you should use the latest code from the git repository because it treats byte[] as a primitive, i.e, if you send a byte[] from Java to Python, you will get a bytearray (or bytes in Python 3) on the Python side. Barthélémy On 03/16/2011 07:48 AM, Nicolò Perino wrote: > Hi, > actually what I am trying to do is a software transactional memory library in Python able to add transactional support to Java programs. > To simplify let's say that I would like to call a commit() operation in the Java program (for example a commit for each object) that call a Python routine that get the object from Python and store it safely, meaning that changes to the object in the Java-side don't reflect the effects in the object stored in the Python-side. Then I could call a restore() operation in the Java object, that take last saved object in the Python-side and replace the current instance of the Java object. > > I know it is a bit writhed or maybe useless, but it is just an experiment. > > bye > > Nicolò Perino > ______ > PhD Student @ USI - Faculty of Informatics > http://www.people.usi.ch/perinon/ > > On 16 Mar 2011, at 12:04, Barthelemy Dagenais wrote: > >> Hi Nicolò, >> >> as Alex says, it is not possible to use deepcopy with a Java object in >> Python and I'm not sure it makes sense anyway. Are you trying to >> dynamically duplicate a Java object graph from Python or...? >> >> With more information about what you are trying to do, we may be able to >> find an alternative. >> >> Barthélémy >> >> On 03/16/2011 06:50 AM, Alex Grönholm wrote: >>> 16.03.2011 12:24, Nicolò Perino kirjoitti: >>>> Hi, >>>> I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: >>>> >>>>>>> stack = gateway.entry_point.getStack() >>>>>>> stack >>>> JavaObject id=o0 >>>>>>> import copy >>>>>>> a = copy.deepcopy(stack) >>>> Traceback (most recent call last): >>>> File "<stdin>", line 1, in<module> >>>> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy >>>> y = copier(memo) >>>> File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ >>>> args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) >>>> File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part >>>> command_part = REFERENCE_TYPE + parameter._get_object_id() >>>> AttributeError: 'dict' object has no attribute '_get_object_id' >>>> >>>> Is there a way to success in coping objects? >>> You'll have to do it on the Java side. The exact method depends on what >>> type you are trying to copy. >>>> Thank you. >>>> Bye >>>> >>>> >>>> Nicolò Perino >>>> ______ >>>> PhD Student @ USI - Faculty of Informatics >>>> http://www.people.usi.ch/perinon/ >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Colocation vs. Managed Hosting >>>> A question and answer guide to determining the best fit >>>> for your organization - today and in the future. >>>> http://p.sf.net/sfu/internap-sfd2d >>>> _______________________________________________ >>>> Py4j-users mailing list >>>> Py4...@li... >>>> https://lists.sourceforge.net/lists/listinfo/py4j-users >>> >>> >>> ------------------------------------------------------------------------------ >>> Colocation vs. Managed Hosting >>> A question and answer guide to determining the best fit >>> for your organization - today and in the future. >>> http://p.sf.net/sfu/internap-sfd2d >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users >> >> >> ------------------------------------------------------------------------------ >> Colocation vs. Managed Hosting >> A question and answer guide to determining the best fit >> for your organization - today and in the future. >> http://p.sf.net/sfu/internap-sfd2d >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Nicolò P. <nic...@us...> - 2011-03-16 11:48:28
|
Hi, actually what I am trying to do is a software transactional memory library in Python able to add transactional support to Java programs. To simplify let's say that I would like to call a commit() operation in the Java program (for example a commit for each object) that call a Python routine that get the object from Python and store it safely, meaning that changes to the object in the Java-side don't reflect the effects in the object stored in the Python-side. Then I could call a restore() operation in the Java object, that take last saved object in the Python-side and replace the current instance of the Java object. I know it is a bit writhed or maybe useless, but it is just an experiment. bye Nicolò Perino ______ PhD Student @ USI - Faculty of Informatics http://www.people.usi.ch/perinon/ On 16 Mar 2011, at 12:04, Barthelemy Dagenais wrote: > Hi Nicolò, > > as Alex says, it is not possible to use deepcopy with a Java object in > Python and I'm not sure it makes sense anyway. Are you trying to > dynamically duplicate a Java object graph from Python or...? > > With more information about what you are trying to do, we may be able to > find an alternative. > > Barthélémy > > On 03/16/2011 06:50 AM, Alex Grönholm wrote: >> 16.03.2011 12:24, Nicolò Perino kirjoitti: >>> Hi, >>> I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: >>> >>>>>> stack = gateway.entry_point.getStack() >>>>>> stack >>> JavaObject id=o0 >>>>>> import copy >>>>>> a = copy.deepcopy(stack) >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in<module> >>> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy >>> y = copier(memo) >>> File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ >>> args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) >>> File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part >>> command_part = REFERENCE_TYPE + parameter._get_object_id() >>> AttributeError: 'dict' object has no attribute '_get_object_id' >>> >>> Is there a way to success in coping objects? >> You'll have to do it on the Java side. The exact method depends on what >> type you are trying to copy. >>> Thank you. >>> Bye >>> >>> >>> Nicolò Perino >>> ______ >>> PhD Student @ USI - Faculty of Informatics >>> http://www.people.usi.ch/perinon/ >>> >>> >>> ------------------------------------------------------------------------------ >>> Colocation vs. Managed Hosting >>> A question and answer guide to determining the best fit >>> for your organization - today and in the future. >>> http://p.sf.net/sfu/internap-sfd2d >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users >> >> >> ------------------------------------------------------------------------------ >> Colocation vs. Managed Hosting >> A question and answer guide to determining the best fit >> for your organization - today and in the future. >> http://p.sf.net/sfu/internap-sfd2d >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Barthelemy D. <ba...@cs...> - 2011-03-16 11:35:38
|
Hi Nicolò, as Alex says, it is not possible to use deepcopy with a Java object in Python and I'm not sure it makes sense anyway. Are you trying to dynamically duplicate a Java object graph from Python or...? With more information about what you are trying to do, we may be able to find an alternative. Barthélémy On 03/16/2011 06:50 AM, Alex Grönholm wrote: > 16.03.2011 12:24, Nicolò Perino kirjoitti: >> Hi, >> I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: >> >>>>> stack = gateway.entry_point.getStack() >>>>> stack >> JavaObject id=o0 >>>>> import copy >>>>> a = copy.deepcopy(stack) >> Traceback (most recent call last): >> File "<stdin>", line 1, in<module> >> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy >> y = copier(memo) >> File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ >> args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) >> File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part >> command_part = REFERENCE_TYPE + parameter._get_object_id() >> AttributeError: 'dict' object has no attribute '_get_object_id' >> >> Is there a way to success in coping objects? > You'll have to do it on the Java side. The exact method depends on what > type you are trying to copy. >> Thank you. >> Bye >> >> >> Nicolò Perino >> ______ >> PhD Student @ USI - Faculty of Informatics >> http://www.people.usi.ch/perinon/ >> >> >> ------------------------------------------------------------------------------ >> Colocation vs. Managed Hosting >> A question and answer guide to determining the best fit >> for your organization - today and in the future. >> http://p.sf.net/sfu/internap-sfd2d >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Alex G. <ale...@ne...> - 2011-03-16 10:51:23
|
16.03.2011 12:24, Nicolò Perino kirjoitti: > Hi, > I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: > >>>> stack = gateway.entry_point.getStack() >>>> stack > JavaObject id=o0 >>>> import copy >>>> a = copy.deepcopy(stack) > Traceback (most recent call last): > File "<stdin>", line 1, in<module> > File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy > y = copier(memo) > File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ > args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) > File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part > command_part = REFERENCE_TYPE + parameter._get_object_id() > AttributeError: 'dict' object has no attribute '_get_object_id' > > Is there a way to success in coping objects? You'll have to do it on the Java side. The exact method depends on what type you are trying to copy. > Thank you. > Bye > > > Nicolò Perino > ______ > PhD Student @ USI - Faculty of Informatics > http://www.people.usi.ch/perinon/ > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Nicolò P. <nic...@us...> - 2011-03-16 10:24:33
|
Hi, I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: >>> stack = gateway.entry_point.getStack() >>> stack JavaObject id=o0 >>> import copy >>> a = copy.deepcopy(stack) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy y = copier(memo) File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part command_part = REFERENCE_TYPE + parameter._get_object_id() AttributeError: 'dict' object has no attribute '_get_object_id' Is there a way to success in coping objects? Thank you. Bye Nicolò Perino ______ PhD Student @ USI - Faculty of Informatics http://www.people.usi.ch/perinon/ |
From: Barthelemy D. <ba...@us...> - 2011-02-17 13:17:21
|
Py4J 0.6 has just been released! This release includes the following new (and great) features: - New exception, Py4JJavaError, that enables Python client programs to access instance of Java exception thrown in the Java client code. - Improved Py4J setup: no more warnings displayed when installing Py4J. - Bug fixes and API additions. I invite you to take a look at the 0.6 change log: https://github.com/bartdag/py4j/issues/labels/v0.6 In case you did not notice, Py4J moved to github so contributing is now easier than ever! I plan to do at least another release (0.7) before Py4J leaves beta and moves to 1.0. Cheers, Barthélémy *About Py4J* Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects. Py4J is distributed under the BSD license. |
From: Barthelemy D. <ba...@us...> - 2011-01-21 15:16:18
|
> Initially I was thinking about accessing it directly as and attribute > which seems a bit more pythonic. > But yes. That's the kind of way of doing it I had in mind. I don't see a straightforward way to merge a Python Exception and a Java Exception together like Py4J does for the collection classes, because you often explicitly mention the class name when catching an exception. For example, it would not be easy to support: try: javaObject.doSomething() except NullPointerException: ... To make this work, this kind of code would be required before catching the exception: NUllPointerException = gateway.jvm.NullPointerException._asPythonClass() Another alternative is to convert any java.lang.Throwable object to Py4JJavaError and to do something like: try: javaObject.doSomething() except Py4JJavaError as e: e.printStackTrace() I think this is what you had in mind, but I am reluctant to collapse the whole Java exception hierarchy into a single Python class and to merge Python and Java exceptions together (e.g., Python exceptions often have a args and with_traceback members, which would hide similar members in a Java exception). I'll have to think about this more. Barthélémy On 01/21/2011 09:29 AM, Jakub Gustak wrote: >> Hi, >> >> I agree with you, exceptions in some Java Library/Framework carry >> important information that should be available on the Python side. >> >> Py4J could wrap the Java Exception in the Py4JJavaError exception, a new >> class extending Py4JError. >> >> Something like: >> >> try: >> ... >> except Py4JJavaError as e: >> javaException = e.getJavaException() > > Initially I was thinking about accessing it directly as and attribute > which seems a bit more pythonic. > But yes. That's the kind of way of doing it I had in mind. > >> That would allow clients to differentiate between catching Java >> exceptions and catching Py4J exceptions (e.g., misuse of the library, >> network error, etc.). Clients could still use the catch all: >> >> except Py4JError: >> >> to catch any exception raised while using Py4J, Java exceptions included. >> >> I just need to make sure that there is no Python black magic that >> prevents the Python exception from being garbage collected. > > I wouldn't expect that. > > I assume (guessed without looking at the code actually) that as long > as python keeps a refernce to java object, java keeps it's reference > as well, and if python object get's garbage collected then java side > is notified so it can collect it's garbage too. It that right? > >> Would that work with your use case? > > In short - yes. > >> >> Barthélémy >> >> On 01/21/2011 06:42 AM, Jakub Gustak wrote: >>> I would like to propose a enhancement to a py4j. >>> >>> Right now the only way to get any info about java side exception is to >>> parse a error message string. >>> It would be quite convenient to be able to access the original java >>> exception object. >>> >>> As far as I understand the code it would require ReturnObject which >>> would be a hybrid of error and reference. >>> Is there any java side limitation than can make it hard to achieve? >>> >>> Best regards, >>> Jakub > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Jakub G. <jg...@gm...> - 2011-01-21 14:29:53
|
> Hi, > > I agree with you, exceptions in some Java Library/Framework carry > important information that should be available on the Python side. > > Py4J could wrap the Java Exception in the Py4JJavaError exception, a new > class extending Py4JError. > > Something like: > > try: > ... > except Py4JJavaError as e: > javaException = e.getJavaException() Initially I was thinking about accessing it directly as and attribute which seems a bit more pythonic. But yes. That's the kind of way of doing it I had in mind. > That would allow clients to differentiate between catching Java > exceptions and catching Py4J exceptions (e.g., misuse of the library, > network error, etc.). Clients could still use the catch all: > > except Py4JError: > > to catch any exception raised while using Py4J, Java exceptions included. > > I just need to make sure that there is no Python black magic that > prevents the Python exception from being garbage collected. I wouldn't expect that. I assume (guessed without looking at the code actually) that as long as python keeps a refernce to java object, java keeps it's reference as well, and if python object get's garbage collected then java side is notified so it can collect it's garbage too. It that right? > Would that work with your use case? In short - yes. > > Barthélémy > > On 01/21/2011 06:42 AM, Jakub Gustak wrote: >> I would like to propose a enhancement to a py4j. >> >> Right now the only way to get any info about java side exception is to >> parse a error message string. >> It would be quite convenient to be able to access the original java >> exception object. >> >> As far as I understand the code it would require ReturnObject which >> would be a hybrid of error and reference. >> Is there any java side limitation than can make it hard to achieve? >> >> Best regards, >> Jakub |
From: Barthelemy D. <ba...@cs...> - 2011-01-21 13:03:07
|
Hi, I agree with you, exceptions in some Java Library/Framework carry important information that should be available on the Python side. Py4J could wrap the Java Exception in the Py4JJavaError exception, a new class extending Py4JError. Something like: try: ... except Py4JJavaError as e: javaException = e.getJavaException() That would allow clients to differentiate between catching Java exceptions and catching Py4J exceptions (e.g., misuse of the library, network error, etc.). Clients could still use the catch all: except Py4JError: to catch any exception raised while using Py4J, Java exceptions included. I just need to make sure that there is no Python black magic that prevents the Python exception from being garbage collected. Would that work with your use case? Barthélémy On 01/21/2011 06:42 AM, Jakub Gustak wrote: > I would like to propose a enhancement to a py4j. > > Right now the only way to get any info about java side exception is to > parse a error message string. > It would be quite convenient to be able to access the original java > exception object. > > As far as I understand the code it would require ReturnObject which > would be a hybrid of error and reference. > Is there any java side limitation than can make it hard to achieve? > > Best regards, > Jakub > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Jakub G. <jg...@gm...> - 2011-01-21 11:42:20
|
I would like to propose a enhancement to a py4j. Right now the only way to get any info about java side exception is to parse a error message string. It would be quite convenient to be able to access the original java exception object. As far as I understand the code it would require ReturnObject which would be a hybrid of error and reference. Is there any java side limitation than can make it hard to achieve? Best regards, Jakub |
From: Jakub G. <jg...@gm...> - 2011-01-20 12:03:48
|
> Hi Jakub, > > There should be an exception thrown by Java if a GatewayServer is started > on a port already in used. If there is no exception thrown, then it is a > bug. > > If you have time, could you fill a bug report with information about the > current version of Py4J, the OS you are using, and a small snippet to > reproduce the problem: > > https://github.com/bartdag/py4j > > In any case, I'll probably look at this issue tomorrow or Friday. Here goes the issue with suggested fix for python side (since I am more of a python than java developer) and java code snippet to reproduce: https://github.com/bartdag/py4j/issues/issue/77 Thanks, Jakub |
From: Jakub G. <jg...@gm...> - 2011-01-18 16:23:49
|
hello, In course of Py4J usage I find it very helpful piece of library but science I use it in slightly more complicated environment as 1-1 python java communication I stumbled upon several problems. The most important one is when you start java GatewayServer and particular port is already in use it does not tell you about it explicitly, I'd expect it to throw in this case actually rather than log it an continue like nothing happned. Python CallbackServer shares the same behavior. Can we think about changing it? -- Jakub |
From: Barthelemy D. <ba...@us...> - 2010-10-30 14:32:24
|
Py4J 0.5 has just been released! This release includes the following new (and great) features: - Import packages (e.g., java_import(gateway.jvm, 'java.io.*')) - Filter the help content (e.g., gateway.help(obj,'get*Foo*Bar')) - Automatically convert Python collections (list, set, dictionary) to Java collections. - Py4J Eclipse update site: http://py4j.sourceforge.net/py4j_eclipse I invite you to take a look at the 0.5 change log: http://py4j.sourceforge.net/changelog.html#py4j-0-5 Cheers, Barthélémy *About Py4J* Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects. Py4J is distributed under the BSD license. |
From: Barthelemy D. <ba...@us...> - 2010-09-19 14:53:29
|
Py4J 0.4 has just been released! This release includes many critical bug fixes and a few new features. Since the beginning of Py4J, I have been trying to release early and often and to release on a regular basis (2 months). Unfortunately, because I have been extremely busy during the summer, I have made the mistake of pushing back the release date in the hope that it would give me time to complete all the tickets for 0.4. This is **not** how it should work. The next release is due in 6 weeks and even if there is only one new bug fix or one new feature, it will be released at that date. In the meantime, I invite you to take a look at the 0.4 change log: http://py4j.sourceforge.net/changelog.html#py4j-0-4 Cheers, Barthélémy *About Py4J* Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects. Py4J is distributed under the BSD license. |
From: Barthelemy D. <ba...@us...> - 2010-04-27 20:44:21
|
Py4J 0.3 has just been released. This is a major milestone for Py4J. This release introduces a new callback feature: Java objects can now call Python objects that implement a Java interface. See the change log here: http://py4j.sourceforge.net/changelog.html#py4j-0-3 Barthélémy *About Py4J* Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects. Py4J is distributed under the BSD license. |
From: Barthelemy D. <ba...@us...> - 2010-02-11 20:21:25
|
Py4J 0.2 has just been released. This is the second release of Py4J. This release includes a bunch of new features such as calling constructors and static members. Java Maps can now be used like Python dictionary. See the change log here: http://py4j.sourceforge.net/changelog.html#py4j-0-2 Barthélémy *About Py4J* Py4J enables Python programs running in a Python interpreter to dynamically access Java objects residing in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J is distributed under the BSD license. |
From: Barthelemy D. <ba...@us...> - 2009-12-23 16:37:42
|
Py4J has just been released. This is the first release of Py4J. Basic features such as calling methods of Java objects and treating Java lists like Python lists are implemented. See the change log here: http://py4j.sourceforge.net/changelog.html#py4j-0-1 Rejoice! Barthélémy *About Py4J* Py4J enables Python programs to dynamically access arbitrary Java objects. Methods are called as if the Java objects resided in the Python virtual machine. There is no code to generate and no interface to implement for shared objects on both sides. |