py4j-users Mailing List for Py4J (Page 3)
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: listserve <tom...@gm...> - 2014-12-08 16:39:16
|
Hello, I'm trying to run the code in the docs from here: http://py4j.sourceforge.net/getting_started.html#writing-the-java-program I'm not that experienced with Java so I may very well be making a mistake unrelated to py4j, but I'm unable to run the code regardless. This is what I've done: I saved the Stack code in a file called Stack.java and the other code in StackEntryPoint.java. I compiled it at the command line with the following: JARFILE=/usr/local/share/py4j/py4j0.8.2.1.jar javac -cp $JARFILE *.java That gave no error. I then tried to run it with: java -cp $JARFILE:. StackEntryPoint and I get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: StackEntryPoint (wrong name: py4j/examples/StackEntryPoint) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482) I am running Linux Mint 17 (which is basically Ubuntu) and the following is my versions of java/javac: $ java -version java version "1.7.0_65" OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode) $ javac -version javac 1.7.0_65 Thanks for any help. Cheers, Thomas |
From: Barthelemy D. <bar...@in...> - 2014-12-05 13:35:24
|
Hi, So I made a small mistake when replying, but the documentation is actually correct. "get_field" is a function declared in the py4j.java_gateway module and not a method of the JavaGateway object. So you need to call: from py4j.java_gateway import get_field get_field(obj, "field_name") Also, this only works for publicly accessible fields. Private/Package/Protected fields won't be accessible. For instance, py4j.examples.Stack has no public fields. When you do "stack.test3", py4j cannot resolve "test3" to a field, so instead, it creates a JavaMember in an attempt to resolve it later (ex: maybe it's a method, an internal class, etc.). Hope this helps, Barthelemy On Thu Dec 04 2014 at 9:09:53 PM Wilfried Fauvel <wil...@gm...> wrote: > Hi, > > thank you for your fast answer ! > > I added : c = gateway.get_field(stack, 'test3') > but then it raises : > > Traceback (most recent call last): > File "test.py", line 22, in <module> > main() > File "test.py", line 18, in main > c = gateway.get_field(stack, 'test3') > File "/usr/lib/python2.7/site-packages/py4j/java_gateway.py", line > 538, in __call__ > self.target_id, self.name) > File "/usr/lib/python2.7/site-packages/py4j/protocol.py", line 304, > in get_return_value > format(target_id, '.', name, value)) > py4j.protocol.Py4JError: An error occurred while calling t.get_field. > Trace: > py4j.Py4JException: Method get_field([class py4j.examples.Stack, class > java.lang.String]) does not exist > at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:333) > at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:342) > at py4j.Gateway.invoke(Gateway.java:252) > at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133) > at py4j.commands.CallCommand.execute(CallCommand.java:79) > at py4j.GatewayConnection.run(GatewayConnection.java:207) > at java.lang.Thread.run(Thread.java:745) > > and auto_field=True returns <py4j.java_gateway.JavaMember object at > 0x7f2d7ce7aa10> > > I am using : pip2.7 show py4j > --- > Name: py4j > Version: 0.8.2.1 > Location: /usr/lib/python2.7/site-packages > Requires: > > and > > java version "1.7.0_71" > OpenJDK Runtime Environment (IcedTea 2.5.3) (Arch Linux build > 7.u71_2.5.3-1-x86_64) > OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode) > > Thank you. > > On Thu, Dec 4, 2014 at 5:23 AM, Barthelemy Dagenais > <bar...@in...> wrote: > > Hi! > > > > Thanks for using Py4J! > > > > To access fields, you can either use gateway.get_field(object, "test1") > or > > set auto_field=True when initializing the gateway to access object.test1. > > > > Reference: http://py4j.sourceforge.net/faq.html#how-to-access-a-field > > > > auto_field is False by default because it costs an extra lookup. > > > > Barthelemy > > > > On Wed Dec 03 2014 at 10:30:12 PM Wilfried Fauvel > > <wil...@gm...> wrote: > >> > >> Hi, I am testing py4j and I would like to know if it is possible to > >> access class attributes. > >> In the Stack class from the getting started page, I added : > >> > >> public static final String test1 = "TEST"; > >> public static final int test2 = 12; > >> public int test3 = 12; > >> > >> and with python 2.7 : > >> > >> gateway = JavaGateway() > >> stack = gateway.entry_point.getStack() > >> print(gateway.help(stack)) > >> >>> field section is empty > >> > >> print stack.test1 > >> print stack.test2 > >> print stack.test3 > >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647250> > >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647a10> > >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b16479d0> > >> > >> Thank you, > >> Wilfried. > >> > >> > >> ------------------------------------------------------------ > ------------------ > >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards > >> with Interactivity, Sharing, Native Excel Exports, App Integration & > more > >> Get technology previously reserved for billion-dollar corporations, FREE > >> > >> http://pubads.g.doubleclick.net/gampad/clk?id=164703151& > iu=/4140/ostg.clktrk > >> _______________________________________________ > >> Py4j-users mailing list > >> Py4...@li... > >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > > > > ------------------------------------------------------------ > ------------------ > > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > > with Interactivity, Sharing, Native Excel Exports, App Integration & more > > Get technology previously reserved for billion-dollar corporations, FREE > > http://pubads.g.doubleclick.net/gampad/clk?id=164703151& > iu=/4140/ostg.clktrk > > _______________________________________________ > > Py4j-users mailing list > > Py4...@li... > > https://lists.sourceforge.net/lists/listinfo/py4j-users > > > > ------------------------------------------------------------ > ------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=164703151& > iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Wilfried F. <wil...@gm...> - 2014-12-05 02:10:20
|
Hi, thank you for your fast answer ! I added : c = gateway.get_field(stack, 'test3') but then it raises : Traceback (most recent call last): File "test.py", line 22, in <module> main() File "test.py", line 18, in main c = gateway.get_field(stack, 'test3') File "/usr/lib/python2.7/site-packages/py4j/java_gateway.py", line 538, in __call__ self.target_id, self.name) File "/usr/lib/python2.7/site-packages/py4j/protocol.py", line 304, in get_return_value format(target_id, '.', name, value)) py4j.protocol.Py4JError: An error occurred while calling t.get_field. Trace: py4j.Py4JException: Method get_field([class py4j.examples.Stack, class java.lang.String]) does not exist at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:333) at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:342) at py4j.Gateway.invoke(Gateway.java:252) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.GatewayConnection.run(GatewayConnection.java:207) at java.lang.Thread.run(Thread.java:745) and auto_field=True returns <py4j.java_gateway.JavaMember object at 0x7f2d7ce7aa10> I am using : pip2.7 show py4j --- Name: py4j Version: 0.8.2.1 Location: /usr/lib/python2.7/site-packages Requires: and java version "1.7.0_71" OpenJDK Runtime Environment (IcedTea 2.5.3) (Arch Linux build 7.u71_2.5.3-1-x86_64) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode) Thank you. On Thu, Dec 4, 2014 at 5:23 AM, Barthelemy Dagenais <bar...@in...> wrote: > Hi! > > Thanks for using Py4J! > > To access fields, you can either use gateway.get_field(object, "test1") or > set auto_field=True when initializing the gateway to access object.test1. > > Reference: http://py4j.sourceforge.net/faq.html#how-to-access-a-field > > auto_field is False by default because it costs an extra lookup. > > Barthelemy > > On Wed Dec 03 2014 at 10:30:12 PM Wilfried Fauvel > <wil...@gm...> wrote: >> >> Hi, I am testing py4j and I would like to know if it is possible to >> access class attributes. >> In the Stack class from the getting started page, I added : >> >> public static final String test1 = "TEST"; >> public static final int test2 = 12; >> public int test3 = 12; >> >> and with python 2.7 : >> >> gateway = JavaGateway() >> stack = gateway.entry_point.getStack() >> print(gateway.help(stack)) >> >>> field section is empty >> >> print stack.test1 >> print stack.test2 >> print stack.test3 >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647250> >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647a10> >> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b16479d0> >> >> Thank you, >> Wilfried. >> >> >> ------------------------------------------------------------------------------ >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >> with Interactivity, Sharing, Native Excel Exports, App Integration & more >> Get technology previously reserved for billion-dollar corporations, FREE >> >> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Barthelemy D. <bar...@in...> - 2014-12-04 10:23:40
|
Hi! Thanks for using Py4J! To access fields, you can either use gateway.get_field(object, "test1") or set auto_field=True when initializing the gateway to access object.test1. Reference: http://py4j.sourceforge.net/faq.html#how-to-access-a-field auto_field is False by default because it costs an extra lookup. Barthelemy On Wed Dec 03 2014 at 10:30:12 PM Wilfried Fauvel <wil...@gm...> wrote: > Hi, I am testing py4j and I would like to know if it is possible to > access class attributes. > In the Stack class from the getting started page, I added : > > public static final String test1 = "TEST"; > public static final int test2 = 12; > public int test3 = 12; > > and with python 2.7 : > > gateway = JavaGateway() > stack = gateway.entry_point.getStack() > print(gateway.help(stack)) > >>> field section is empty > > print stack.test1 > print stack.test2 > print stack.test3 > >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647250> > >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647a10> > >>> <py4j.java_gateway.JavaMember object at 0x7fd7b16479d0> > > Thank you, > Wilfried. > > ------------------------------------------------------------ > ------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=164703151& > iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Wilfried F. <wil...@gm...> - 2014-12-04 03:30:39
|
Hi, I am testing py4j and I would like to know if it is possible to access class attributes. In the Stack class from the getting started page, I added : public static final String test1 = "TEST"; public static final int test2 = 12; public int test3 = 12; and with python 2.7 : gateway = JavaGateway() stack = gateway.entry_point.getStack() print(gateway.help(stack)) >>> field section is empty print stack.test1 print stack.test2 print stack.test3 >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647250> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b1647a10> >>> <py4j.java_gateway.JavaMember object at 0x7fd7b16479d0> Thank you, Wilfried. |
From: Barthelemy D. <bar...@in...> - 2014-10-26 00:52:12
|
Hi, I am receiving many reasonable requests to make JavaGateway and JavaCallbackServer more configurable. Clearly, sending all parameters to the JavaGateway constructor does not scale, so I created two classes, GatewayParameters and CallbackServerParameters. These classes are available in @master and will be the recommended way to configure a gateway in Py4J 0.9. The existing parameters can be set in these two new classes in addition to new parameters. I am deprecating the other JavaGateway constructor parameters (e.g., port, auto_field, start_callback_server), which means that I would like to remove the parameters in two releases. If you use these parameters in 0.9, the behavior of Py4J should not change: if the behavior changes, it's a regression bug and I'll fix it asap. The only difference with 0.8 is that a log statement (level=DEBUG) will tell you that the parameter is deprecated. In Py4J 0.10, the log statement will use the WARNING level. In 0.11, an exception will be raised if you use the deprecated parameters. In 0.12 (or 1.0), these parameters will be completely removed. If there is any concern regarding this deprecation procedure, I'm open to suggestions to improve it. Finally, on the deprecation topic, someone recently asked me if I still planned to support Python 2.6. I had initially planned to stop supporting this old version of Python, but considering that users are still deploying Py4J in environments where Python 2.6 is the default version, and because I do not specifically need any features introduced in later versions, I'll continue to (1) support Python 2.6, and (2) beg users to install virtualenv with a more recent version of Python :-D Barthélémy |
From: Mingda Z. <sd...@16...> - 2014-08-20 02:14:40
|
Thank you, Barthelemy. I have solved my problem by creating an array using gateway.new_array. What a powerful tool! Best regards, Mingda At 2014-08-19 05:50:57, "Barthelemy Dagenais" <bar...@in...> wrote: >Hi, > >Thanks for using Py4j! > >Py4J supports automated conversion to Java lists, sets, and maps, but >not array: http://py4j.sourceforge.net/advanced_topics.html#converting-python-collections-to-java-collections > >You can still create an array from Py4J using gateway.new_array >(http://py4j.sourceforge.net/faq.html#how-to-create-an-array). > >If you want Py4J to support automated conversion to Java arrays, you >can open an issue on github with an example of your use case. > >There are a few challenges with automatically converting to Java >collections and to Java arrays in particular, but it might be possible >to create a converter for common cases. > >Cheers, >Barthelemy > >On Mon, Aug 18, 2014 at 10:57 PM, Mingda Zhang <sd...@16...> wrote: >> Hi, >> Py4J is a great project to access Java objects. Py4J can covert Python >> collections to Java collections easily. But now, I need to convert the >> Python collections to Java array (The Input parameters of methods in Java >> are array ). Could anyone tell me how to do this with Py4J? Thank you very >> much. >> Best regards, >> Mingda Zhang >> >> >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users >> > >------------------------------------------------------------------------------ >_______________________________________________ >Py4j-users mailing list >Py4...@li... >https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Barthelemy D. <bar...@in...> - 2014-08-19 09:51:04
|
Hi, Thanks for using Py4j! Py4J supports automated conversion to Java lists, sets, and maps, but not array: http://py4j.sourceforge.net/advanced_topics.html#converting-python-collections-to-java-collections You can still create an array from Py4J using gateway.new_array (http://py4j.sourceforge.net/faq.html#how-to-create-an-array). If you want Py4J to support automated conversion to Java arrays, you can open an issue on github with an example of your use case. There are a few challenges with automatically converting to Java collections and to Java arrays in particular, but it might be possible to create a converter for common cases. Cheers, Barthelemy On Mon, Aug 18, 2014 at 10:57 PM, Mingda Zhang <sd...@16...> wrote: > Hi, > Py4J is a great project to access Java objects. Py4J can covert Python > collections to Java collections easily. But now, I need to convert the > Python collections to Java array (The Input parameters of methods in Java > are array ). Could anyone tell me how to do this with Py4J? Thank you very > much. > Best regards, > Mingda Zhang > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Mingda Z. <sd...@16...> - 2014-08-19 02:57:23
|
Hi, Py4J is a great project to access Java objects. Py4J can covert Python collections to Java collections easily. But now, I need to convert the Python collections to Java array (The Input parameters of methods in Java are array ). Could anyone tell me how to do this with Py4J? Thank you very much. Best regards, Mingda Zhang |
From: Barthelemy D. <bar...@in...> - 2014-07-28 00:07:25
|
Hi, this is a minor bugfix release. This release includes the following new features: - Fixed constructors not being able to pass proxy (python classes implementing Java interfaces) - Java 6 compatibility was restored in compiled jar file. - Fixed unit tests for JDK 8 - Added a few extra paths to find_jar_path I made a hotfix (0.8.2.1) because an assert method I was using did not exist in Python 2.6 and this version is still officially supported by Py4J. Installing Py4J is one pip away: pip install py4j Again, feel free to contact me or to write a feature request on GitHub! Cheers, Barthélémy |
From: Barthelemy D. <bar...@in...> - 2014-07-27 17:34:14
|
Hi, in the coming weeks, I'll be creating the py4j-eclipse repository and I'll move all the eclipse-related subprojects from the main py4j repository to this new repository. I'll preserve the git history in py4j-eclipse, but I'll strip the history related to the eclipse subprojects in the py4j repository. This move has a few advantages: 1. I'll use a git submodule to load the source files of py4j in py4j-eclipse. This will simplify pull requests and contributions. Currently, the source is duplicated between py4j-java and net.sf.py4j because of a ugly hack and I always have to port pull requests made on net.sf.py4j to py4j-java. 2. If someone wants to take ownership of py4j-eclipse, I'll gladly hand it over. I have not been using Eclipse for a long time and I don't have the time to actively maintain this subproject. Having a separate repository will make this process easier. 3. Because the main repository will be smaller, I will add a setup.py in the root of the py4j repository to make it installable with pip. If someone sees any issue with this move, do not hesitate to contact me through the mailing list. Btw, I'll be making a minor release today. Cheers, Barthelemy |
From: Jeremy <ken...@gm...> - 2014-05-18 03:01:18
|
Hah, turns out it was the missing 'self.' changed it to self.__eq__(obj) and it works! (Getting my Java and Python mixed up.) Its great that I can just pass around the interface now. There's one last thing that has been confusing me and that is launching the server using the java_gateway.launch_gateway(). I've been trying to start the app using that instead of manually calling the popen() myself. My directory layout looks like this: root | | -Launcher.py | -MainWindow.py | -Other stuff .py | lib \ | -common-codec.jar | -jackson-core.jar | -py4j-0.8.1.jar | -pctelelog-gateway-server.jar | -Other dependencies for gateway server Looking at the documentation for launch_gateway() I decided to try using this in my Launcher. self.__gateway = JavaGateway.launch_gateway(jarpath="./lib/pctelelog-gateway-server.jar", classpath="pctelelog.TeleLogPy4jLauncher", die_on_exit=True) TeleLogPy4jLauncher.java (inside the pctelelog-gateway-server.jar) package pctelelog; /*Imports*/ public class TeleLogPy4jLauncher implements GatewayServerListener { private static Logger logger = LogManager.getLogger(TeleLogPy4jLauncher.class); private static TeleLogServer m_telelogServer = new TeleLogServer(); public TeleLogPy4jLauncher() { logger.info("Logging started."); m_telelogServer.start(); } public void addEventListener(EventListener listener) { logger.info("Listener added."); m_telelogServer.addEventListener(listener); } public void removeEventListener(EventListener listener) { logger.info("Listener removed."); m_telelogServer.removeEventListener(listener); } public static void main(String[] args) { TeleLogPy4jLauncher launcher = new TeleLogPy4jLauncher(); GatewayServer gateway = new GatewayServer(launcher); gateway.addListener(launcher); gateway.start(); } /* GatewayListener implementations */ } When I run Launcher.py I get a StringIndexOutofBoundsException when the addEventListener is called in my MainWindow initCallback(). If I launch the JAR manually everything works fine. So I feel like there must be something I'm misunderstanding about the way to use launch_gateway. Maybe it won't work with my server inside a jar? Thanks for the help and patience so far! Jeremy On 5/17/14, 5:17 PM, Barthelemy Dagenais wrote: > Hi, > > regarding the equals method, I believe you were in the right direction: > > def equals(self, obj): > # obj will be a JavaObject type, so obj is never equal to self > return obj is not None and obj.toString() == self.toString() > > def toString(self): > return "Something Unique" > > In one of your examples, you call __eq__(obj), but it should be self.__eq__(obj) > > A good practice when you are not sure what is going on is to always > wrap your code in: > > try: > # unsafe code > except Exception: > from traceback import print_exc > print_exc() > > Sometimes, exceptions are swallowed or shadowed by other exceptions > and this is a trick that saved me a lot of time in the past ;-) > > Finally, I'm not sure why you need the setter (vs the constructor with > the parameter). I'll need to investigate and I'll try to get back to > you this week. > > Thanks, > Bart > > > On Fri, May 16, 2014 at 7:35 PM, Jeremy <ken...@gm...> wrote: >> Sorry for the delayed reply. Been busy, finally got time to work on my >> project. >> >> I looked at the Vector.java code and can see that it calls the Object >> class method, equals(). >> So taking your suggestion, I added an equals(Object) method to the >> interface (not necessary likely) and tried to implement something in the >> implementing class in Python. Something like: >> >> class equals(self, obj): >> if self == obj: >> return True >> return False >> >> But still got the same error. Tried adding in Python's global equal, and >> that didn't work either. And even tried creating a UUID for each >> EventListener, but that didn't work either. It just can't seem to find >> the equals method. My final EventListener ended up looking like this. >> >> class EventListener(object): >> id = uuid.uuid4() >> >> def onEvent(self, event): >> pass >> >> def equals(self, obj): >> return __eq__(obj) >> >> def __eq__(self, obj): >> if obj == None: >> return False >> >> if obj.id == self.id: >> return True >> else: >> return False >> >> class Java: >> implements = ['pctelelog.EventListener'] >> >> pass >> >> >> My solution that seems to be working now has been to remove passing >> around an interface and instead rename the interface EventCallback and >> wrap it inside a new class (EventListener) and pass an object of that >> class around. It works fine but I have a strange issue now, maybe I'm >> doing it wrong. >> >> Here's my new EventListener.java >> public class EventListener implements EventCallback { >> >> private EventCallback m_callback = null; >> >> public EventListener() { >> } >> >> public EventListener(EventCallback callback) { >> assert callback != null; >> >> m_callback = callback; >> } >> >> public void setCallback(EventCallback callback) { >> m_callback = callback; >> } >> >> public static EventListener createEventListener(EventCallback >> callback) { >> return new EventListener(callback); >> } >> >> @Override >> public void onEvent(AbstractEvent event) { >> m_callback.onEvent(event); >> } >> } >> >> Here's the Python I use to get an instance of the class and then add it >> to the listener pool: >> (This method sits inside a PyQt Widget class.) >> >> def initCallback(self, func): >> callback = EventCallback() >> callback.onEvent = self.onEvent >> self.eventListener = >> self.__gateway.jvm.pctelelog.EventListener(callback) >> self.__gateway.entry_point.addEventListener(self.eventListener) >> >> >> When I try to do it like that I get an error (Logger + Error): >> >> Callback Server Starting >> Socket listening on ('127.0.0.1', 25334) >> Command to send: r >> u >> pctelelog >> rj >> e >> >> Answer received: yp >> Command to send: r >> u >> pctelelog.EventListener >> rj >> e >> >> Answer received: ycpctelelog.EventListener >> Traceback (most recent call last): >> File >> "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", >> line 27, in <module> >> Launcher() >> File >> "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", >> line 23, in __init__ >> mainWindow = MainWindow(self.__gateway) >> File >> "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", >> line 25, in __init__ >> self.initCallback(self.onEvent) >> File >> "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", >> line 49, in initCallback >> self.eventListener = >> self.__gateway.jvm.pctelelog.EventListener(callback) >> File "/usr/local/lib/python2.7/site-packages/py4j/java_gateway.py", >> line 662, in __call__ >> args_command = ''.join([get_command_part(arg) for arg in args]) >> File "/usr/local/lib/python2.7/site-packages/py4j/protocol.py", line >> 261, in get_command_part >> command_part = PYTHON_PROXY_TYPE + python_proxy_pool.put(parameter) >> AttributeError: 'NoneType' object has no attribute 'put' >> >> === >> Now, if I change it around and instantiate with the void constructor and >> set the callback with the setter. It works fine. >> >> def initCallback(self, func): >> callback = EventCallback() >> callback.onEvent = self.onEvent >> self.eventListener = self.__gateway.jvm.pctelelog.EventListener() >> self.eventListener.setCallback(callback) >> self.__gateway.entry_point.addEventListener(self.eventListener) >> >> I'd rather do without the setter if there was a way to manage it. Any >> idea what's going on? >> >> >> Thanks! >> >> On 5/7/14, 7:54 AM, Barthelemy Dagenais wrote: >>> Hi! >>> >>> Thanks for using Py4J! I'll try to look at this issue more deeply >>> during the weekend, but from the stack trace, it seems the Java side >>> is sending a method call to the Python side and the Python side is >>> replying with an exception: >>> >>> Error: >>> py4j.protocol.Py4JJavaError: An error occurred while calling >>> t.removeEventListener. >>> : py4j.Py4JException: An exception was raised by the Python Proxy. >>> Return Message: x >>> >>> Also, from the stack trace, it appears that when deleting the listener >>> from the Java vector, the vector calls the "equals" method on the >>> listener. This is the first time I have to deal with this scenario and >>> I believe the equals method is delegated to the python side. Because >>> it is not implemented, I believe this may be the cause of failure. A >>> workaround might be to try to implement an "equals" method in your >>> Python listener. >>> >>> Do you have logging enabled on the Python side? Any stack trace visible there? >>> >>> Btw, you should subscribe to the mailing list, it would be easier to >>> manage the replies :-) >>> >>> Bart >>> >>> On Tue, May 6, 2014 at 7:58 PM, Jeremy <ken...@gm...> wrote: >>>> So I'm trying to use Py4j to let a UI talk to a Java server. The java >>>> server uses 3 threads (entry-point, server socket, client-event >>>> dispatch). The python UI registers an event call back listener and that >>>> listener eventually gets dumped into a Vector. I had some initial >>>> trouble getting the addEventListener() working but fixed it (somehow). >>>> But now any calls to removeEventListener() don't work. >>>> >>>> My first guess was something to do with different instances of the >>>> object when Vector does the lookup, but I'm not sure. I don't understand >>>> relfection concepts well enough and the Py->Java (callback) thing seems >>>> to suggest I should be fine since the original eventlistener hasn't been >>>> garbage collected yet. If you have any insight that would be great. >>>> >>>> Error: >>>> py4j.protocol.Py4JJavaError: An error occurred while calling >>>> t.removeEventListener. >>>> : py4j.Py4JException: An exception was raised by the Python Proxy. >>>> Return Message: x >>>> at py4j.Protocol.getReturnValue(Protocol.java:417) >>>> at >>>> py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) >>>> at com.sun.proxy.$Proxy0.equals(Unknown Source) >>>> at java.util.Vector.indexOf(Vector.java:404) >>>> at java.util.Vector.indexOf(Vector.java:378) >>>> at java.util.Vector.removeElement(Vector.java:637) >>>> at java.util.Vector.remove(Vector.java:795) >>>> at >>>> pctelelog.EventOperatorThread.removeEventListener(EventOperatorThread.java:20) >>>> at pctelelog.ServerThread.removeEventListener(ServerThread.java:16) >>>> at pctelelog.Launcher.removeEventListener(Launcher.java:17) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at >>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) >>>> >>>> This code is a stripped down version of the development version but both >>>> are generating the same error. >>>> >>>> package pctelelog; >>>> >>>> public class Event { >>>> public String testData = "test"; >>>> } >>>> >>>> === >>>> >>>> package pctelelog; >>>> >>>> public interface EventListener { >>>> public void onEvent(Event event); >>>> } >>>> >>>> === >>>> >>>> package pctelelog; >>>> >>>> import java.util.Vector; >>>> >>>> public class EventOperatorThread extends Thread { >>>> >>>> private Vector<EventListener> m_listeners = new >>>> Vector<EventListener>(); >>>> >>>> public void run() { >>>> while(true) {} >>>> } >>>> >>>> public synchronized void addEventListener(EventListener listener) { >>>> System.out.println("ADD"); >>>> m_listeners.add(listener); >>>> } >>>> >>>> public synchronized void removeEventListener(EventListener listener) { >>>> System.out.println("REMOVE"); >>>> m_listeners.remove(listener); >>>> } >>>> } >>>> >>>> === >>>> >>>> package pctelelog; >>>> >>>> public class ServerThread extends Thread { >>>> >>>> private EventOperatorThread m_operator = new EventOperatorThread(); >>>> >>>> public void run() { >>>> m_operator.start(); >>>> while(true) {} >>>> } >>>> >>>> public synchronized void addEventListener(EventListener listener) { >>>> m_operator.addEventListener(listener); >>>> } >>>> public synchronized void removeEventListener(EventListener listener) { >>>> m_operator.removeEventListener(listener); >>>> } >>>> >>>> } >>>> >>>> === >>>> >>>> package pctelelog; >>>> >>>> import py4j.GatewayServer; >>>> >>>> public class Launcher { >>>> private ServerThread m_server = new ServerThread(); >>>> >>>> public Launcher() { >>>> m_server.start(); >>>> System.out.println("Server started."); >>>> } >>>> >>>> public void addEventListener(EventListener listener) { >>>> m_server.addEventListener(listener); >>>> } >>>> public void removeEventListener(EventListener listener) { >>>> m_server.removeEventListener(listener); >>>> } >>>> >>>> public static void main(String[] args) { >>>> GatewayServer gateway = new GatewayServer(new Launcher()); >>>> gateway.start(); >>>> } >>>> } >>>> >>>> === >>>> >>>> from py4j.java_gateway import JavaGateway, GatewayClient >>>> >>>> class EventListener(object): >>>> >>>> def onEvent(self, event): >>>> print event.testData; >>>> >>>> class Java: >>>> implements = ['pctelelog.EventListener'] >>>> >>>> class Launcher: >>>> >>>> def __init__(self): >>>> self.__gateway = JavaGateway(start_callback_server=True) >>>> listener = EventListener() >>>> self.__gateway.entry_point.addEventListener(listener) >>>> self.__gateway.entry_point.removeEventListener(listener) >>>> >>>> if __name__ == '__main__': >>>> Launcher() >>>> pass >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Is your legacy SCM system holding you back? Join Perforce May 7 to find out: >>>> • 3 signs your SCM is hindering your productivity >>>> • Requirements for releasing software faster >>>> • Expert tips and advice for migrating your SCM now >>>> http://p.sf.net/sfu/perforce >>>> _______________________________________________ >>>> Py4j-users mailing list >>>> Py4...@li... >>>> https://lists.sourceforge.net/lists/listinfo/py4j-users >> >> ------------------------------------------------------------------------------ >> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE >> Instantly run your Selenium tests across 300+ browser/OS combos. >> Get unparalleled scalability from the best Selenium testing platform available >> Simple to use. Nothing to install. Get started now for free." >> http://p.sf.net/sfu/SauceLabs >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > ------------------------------------------------------------------------------ > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE > Instantly run your Selenium tests across 300+ browser/OS combos. > Get unparalleled scalability from the best Selenium testing platform available > Simple to use. Nothing to install. Get started now for free." > http://p.sf.net/sfu/SauceLabs > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Barthelemy D. <bar...@in...> - 2014-05-17 21:18:04
|
Hi, regarding the equals method, I believe you were in the right direction: def equals(self, obj): # obj will be a JavaObject type, so obj is never equal to self return obj is not None and obj.toString() == self.toString() def toString(self): return "Something Unique" In one of your examples, you call __eq__(obj), but it should be self.__eq__(obj) A good practice when you are not sure what is going on is to always wrap your code in: try: # unsafe code except Exception: from traceback import print_exc print_exc() Sometimes, exceptions are swallowed or shadowed by other exceptions and this is a trick that saved me a lot of time in the past ;-) Finally, I'm not sure why you need the setter (vs the constructor with the parameter). I'll need to investigate and I'll try to get back to you this week. Thanks, Bart On Fri, May 16, 2014 at 7:35 PM, Jeremy <ken...@gm...> wrote: > Sorry for the delayed reply. Been busy, finally got time to work on my > project. > > I looked at the Vector.java code and can see that it calls the Object > class method, equals(). > So taking your suggestion, I added an equals(Object) method to the > interface (not necessary likely) and tried to implement something in the > implementing class in Python. Something like: > > class equals(self, obj): > if self == obj: > return True > return False > > But still got the same error. Tried adding in Python's global equal, and > that didn't work either. And even tried creating a UUID for each > EventListener, but that didn't work either. It just can't seem to find > the equals method. My final EventListener ended up looking like this. > > class EventListener(object): > id = uuid.uuid4() > > def onEvent(self, event): > pass > > def equals(self, obj): > return __eq__(obj) > > def __eq__(self, obj): > if obj == None: > return False > > if obj.id == self.id: > return True > else: > return False > > class Java: > implements = ['pctelelog.EventListener'] > > pass > > > My solution that seems to be working now has been to remove passing > around an interface and instead rename the interface EventCallback and > wrap it inside a new class (EventListener) and pass an object of that > class around. It works fine but I have a strange issue now, maybe I'm > doing it wrong. > > Here's my new EventListener.java > public class EventListener implements EventCallback { > > private EventCallback m_callback = null; > > public EventListener() { > } > > public EventListener(EventCallback callback) { > assert callback != null; > > m_callback = callback; > } > > public void setCallback(EventCallback callback) { > m_callback = callback; > } > > public static EventListener createEventListener(EventCallback > callback) { > return new EventListener(callback); > } > > @Override > public void onEvent(AbstractEvent event) { > m_callback.onEvent(event); > } > } > > Here's the Python I use to get an instance of the class and then add it > to the listener pool: > (This method sits inside a PyQt Widget class.) > > def initCallback(self, func): > callback = EventCallback() > callback.onEvent = self.onEvent > self.eventListener = > self.__gateway.jvm.pctelelog.EventListener(callback) > self.__gateway.entry_point.addEventListener(self.eventListener) > > > When I try to do it like that I get an error (Logger + Error): > > Callback Server Starting > Socket listening on ('127.0.0.1', 25334) > Command to send: r > u > pctelelog > rj > e > > Answer received: yp > Command to send: r > u > pctelelog.EventListener > rj > e > > Answer received: ycpctelelog.EventListener > Traceback (most recent call last): > File > "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", > line 27, in <module> > Launcher() > File > "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", > line 23, in __init__ > mainWindow = MainWindow(self.__gateway) > File > "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", > line 25, in __init__ > self.initCallback(self.onEvent) > File > "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", > line 49, in initCallback > self.eventListener = > self.__gateway.jvm.pctelelog.EventListener(callback) > File "/usr/local/lib/python2.7/site-packages/py4j/java_gateway.py", > line 662, in __call__ > args_command = ''.join([get_command_part(arg) for arg in args]) > File "/usr/local/lib/python2.7/site-packages/py4j/protocol.py", line > 261, in get_command_part > command_part = PYTHON_PROXY_TYPE + python_proxy_pool.put(parameter) > AttributeError: 'NoneType' object has no attribute 'put' > > === > Now, if I change it around and instantiate with the void constructor and > set the callback with the setter. It works fine. > > def initCallback(self, func): > callback = EventCallback() > callback.onEvent = self.onEvent > self.eventListener = self.__gateway.jvm.pctelelog.EventListener() > self.eventListener.setCallback(callback) > self.__gateway.entry_point.addEventListener(self.eventListener) > > I'd rather do without the setter if there was a way to manage it. Any > idea what's going on? > > > Thanks! > > On 5/7/14, 7:54 AM, Barthelemy Dagenais wrote: >> Hi! >> >> Thanks for using Py4J! I'll try to look at this issue more deeply >> during the weekend, but from the stack trace, it seems the Java side >> is sending a method call to the Python side and the Python side is >> replying with an exception: >> >> Error: >> py4j.protocol.Py4JJavaError: An error occurred while calling >> t.removeEventListener. >> : py4j.Py4JException: An exception was raised by the Python Proxy. >> Return Message: x >> >> Also, from the stack trace, it appears that when deleting the listener >> from the Java vector, the vector calls the "equals" method on the >> listener. This is the first time I have to deal with this scenario and >> I believe the equals method is delegated to the python side. Because >> it is not implemented, I believe this may be the cause of failure. A >> workaround might be to try to implement an "equals" method in your >> Python listener. >> >> Do you have logging enabled on the Python side? Any stack trace visible there? >> >> Btw, you should subscribe to the mailing list, it would be easier to >> manage the replies :-) >> >> Bart >> >> On Tue, May 6, 2014 at 7:58 PM, Jeremy <ken...@gm...> wrote: >>> So I'm trying to use Py4j to let a UI talk to a Java server. The java >>> server uses 3 threads (entry-point, server socket, client-event >>> dispatch). The python UI registers an event call back listener and that >>> listener eventually gets dumped into a Vector. I had some initial >>> trouble getting the addEventListener() working but fixed it (somehow). >>> But now any calls to removeEventListener() don't work. >>> >>> My first guess was something to do with different instances of the >>> object when Vector does the lookup, but I'm not sure. I don't understand >>> relfection concepts well enough and the Py->Java (callback) thing seems >>> to suggest I should be fine since the original eventlistener hasn't been >>> garbage collected yet. If you have any insight that would be great. >>> >>> Error: >>> py4j.protocol.Py4JJavaError: An error occurred while calling >>> t.removeEventListener. >>> : py4j.Py4JException: An exception was raised by the Python Proxy. >>> Return Message: x >>> at py4j.Protocol.getReturnValue(Protocol.java:417) >>> at >>> py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) >>> at com.sun.proxy.$Proxy0.equals(Unknown Source) >>> at java.util.Vector.indexOf(Vector.java:404) >>> at java.util.Vector.indexOf(Vector.java:378) >>> at java.util.Vector.removeElement(Vector.java:637) >>> at java.util.Vector.remove(Vector.java:795) >>> at >>> pctelelog.EventOperatorThread.removeEventListener(EventOperatorThread.java:20) >>> at pctelelog.ServerThread.removeEventListener(ServerThread.java:16) >>> at pctelelog.Launcher.removeEventListener(Launcher.java:17) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at >>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) >>> >>> This code is a stripped down version of the development version but both >>> are generating the same error. >>> >>> package pctelelog; >>> >>> public class Event { >>> public String testData = "test"; >>> } >>> >>> === >>> >>> package pctelelog; >>> >>> public interface EventListener { >>> public void onEvent(Event event); >>> } >>> >>> === >>> >>> package pctelelog; >>> >>> import java.util.Vector; >>> >>> public class EventOperatorThread extends Thread { >>> >>> private Vector<EventListener> m_listeners = new >>> Vector<EventListener>(); >>> >>> public void run() { >>> while(true) {} >>> } >>> >>> public synchronized void addEventListener(EventListener listener) { >>> System.out.println("ADD"); >>> m_listeners.add(listener); >>> } >>> >>> public synchronized void removeEventListener(EventListener listener) { >>> System.out.println("REMOVE"); >>> m_listeners.remove(listener); >>> } >>> } >>> >>> === >>> >>> package pctelelog; >>> >>> public class ServerThread extends Thread { >>> >>> private EventOperatorThread m_operator = new EventOperatorThread(); >>> >>> public void run() { >>> m_operator.start(); >>> while(true) {} >>> } >>> >>> public synchronized void addEventListener(EventListener listener) { >>> m_operator.addEventListener(listener); >>> } >>> public synchronized void removeEventListener(EventListener listener) { >>> m_operator.removeEventListener(listener); >>> } >>> >>> } >>> >>> === >>> >>> package pctelelog; >>> >>> import py4j.GatewayServer; >>> >>> public class Launcher { >>> private ServerThread m_server = new ServerThread(); >>> >>> public Launcher() { >>> m_server.start(); >>> System.out.println("Server started."); >>> } >>> >>> public void addEventListener(EventListener listener) { >>> m_server.addEventListener(listener); >>> } >>> public void removeEventListener(EventListener listener) { >>> m_server.removeEventListener(listener); >>> } >>> >>> public static void main(String[] args) { >>> GatewayServer gateway = new GatewayServer(new Launcher()); >>> gateway.start(); >>> } >>> } >>> >>> === >>> >>> from py4j.java_gateway import JavaGateway, GatewayClient >>> >>> class EventListener(object): >>> >>> def onEvent(self, event): >>> print event.testData; >>> >>> class Java: >>> implements = ['pctelelog.EventListener'] >>> >>> class Launcher: >>> >>> def __init__(self): >>> self.__gateway = JavaGateway(start_callback_server=True) >>> listener = EventListener() >>> self.__gateway.entry_point.addEventListener(listener) >>> self.__gateway.entry_point.removeEventListener(listener) >>> >>> if __name__ == '__main__': >>> Launcher() >>> pass >>> >>> >>> ------------------------------------------------------------------------------ >>> Is your legacy SCM system holding you back? Join Perforce May 7 to find out: >>> • 3 signs your SCM is hindering your productivity >>> • Requirements for releasing software faster >>> • Expert tips and advice for migrating your SCM now >>> http://p.sf.net/sfu/perforce >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE > Instantly run your Selenium tests across 300+ browser/OS combos. > Get unparalleled scalability from the best Selenium testing platform available > Simple to use. Nothing to install. Get started now for free." > http://p.sf.net/sfu/SauceLabs > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Jeremy <ken...@gm...> - 2014-05-16 23:35:37
|
Sorry for the delayed reply. Been busy, finally got time to work on my project. I looked at the Vector.java code and can see that it calls the Object class method, equals(). So taking your suggestion, I added an equals(Object) method to the interface (not necessary likely) and tried to implement something in the implementing class in Python. Something like: class equals(self, obj): if self == obj: return True return False But still got the same error. Tried adding in Python's global equal, and that didn't work either. And even tried creating a UUID for each EventListener, but that didn't work either. It just can't seem to find the equals method. My final EventListener ended up looking like this. class EventListener(object): id = uuid.uuid4() def onEvent(self, event): pass def equals(self, obj): return __eq__(obj) def __eq__(self, obj): if obj == None: return False if obj.id == self.id: return True else: return False class Java: implements = ['pctelelog.EventListener'] pass My solution that seems to be working now has been to remove passing around an interface and instead rename the interface EventCallback and wrap it inside a new class (EventListener) and pass an object of that class around. It works fine but I have a strange issue now, maybe I'm doing it wrong. Here's my new EventListener.java public class EventListener implements EventCallback { private EventCallback m_callback = null; public EventListener() { } public EventListener(EventCallback callback) { assert callback != null; m_callback = callback; } public void setCallback(EventCallback callback) { m_callback = callback; } public static EventListener createEventListener(EventCallback callback) { return new EventListener(callback); } @Override public void onEvent(AbstractEvent event) { m_callback.onEvent(event); } } Here's the Python I use to get an instance of the class and then add it to the listener pool: (This method sits inside a PyQt Widget class.) def initCallback(self, func): callback = EventCallback() callback.onEvent = self.onEvent self.eventListener = self.__gateway.jvm.pctelelog.EventListener(callback) self.__gateway.entry_point.addEventListener(self.eventListener) When I try to do it like that I get an error (Logger + Error): Callback Server Starting Socket listening on ('127.0.0.1', 25334) Command to send: r u pctelelog rj e Answer received: yp Command to send: r u pctelelog.EventListener rj e Answer received: ycpctelelog.EventListener Traceback (most recent call last): File "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", line 27, in <module> Launcher() File "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/Launcher.py", line 23, in __init__ mainWindow = MainWindow(self.__gateway) File "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", line 25, in __init__ self.initCallback(self.onEvent) File "/Users/Shared/eclipse/workspace/PCTeleLog-PyQt/pytelelog-pyqt/MainWindow.py", line 49, in initCallback self.eventListener = self.__gateway.jvm.pctelelog.EventListener(callback) File "/usr/local/lib/python2.7/site-packages/py4j/java_gateway.py", line 662, in __call__ args_command = ''.join([get_command_part(arg) for arg in args]) File "/usr/local/lib/python2.7/site-packages/py4j/protocol.py", line 261, in get_command_part command_part = PYTHON_PROXY_TYPE + python_proxy_pool.put(parameter) AttributeError: 'NoneType' object has no attribute 'put' === Now, if I change it around and instantiate with the void constructor and set the callback with the setter. It works fine. def initCallback(self, func): callback = EventCallback() callback.onEvent = self.onEvent self.eventListener = self.__gateway.jvm.pctelelog.EventListener() self.eventListener.setCallback(callback) self.__gateway.entry_point.addEventListener(self.eventListener) I'd rather do without the setter if there was a way to manage it. Any idea what's going on? Thanks! On 5/7/14, 7:54 AM, Barthelemy Dagenais wrote: > Hi! > > Thanks for using Py4J! I'll try to look at this issue more deeply > during the weekend, but from the stack trace, it seems the Java side > is sending a method call to the Python side and the Python side is > replying with an exception: > > Error: > py4j.protocol.Py4JJavaError: An error occurred while calling > t.removeEventListener. > : py4j.Py4JException: An exception was raised by the Python Proxy. > Return Message: x > > Also, from the stack trace, it appears that when deleting the listener > from the Java vector, the vector calls the "equals" method on the > listener. This is the first time I have to deal with this scenario and > I believe the equals method is delegated to the python side. Because > it is not implemented, I believe this may be the cause of failure. A > workaround might be to try to implement an "equals" method in your > Python listener. > > Do you have logging enabled on the Python side? Any stack trace visible there? > > Btw, you should subscribe to the mailing list, it would be easier to > manage the replies :-) > > Bart > > On Tue, May 6, 2014 at 7:58 PM, Jeremy <ken...@gm...> wrote: >> So I'm trying to use Py4j to let a UI talk to a Java server. The java >> server uses 3 threads (entry-point, server socket, client-event >> dispatch). The python UI registers an event call back listener and that >> listener eventually gets dumped into a Vector. I had some initial >> trouble getting the addEventListener() working but fixed it (somehow). >> But now any calls to removeEventListener() don't work. >> >> My first guess was something to do with different instances of the >> object when Vector does the lookup, but I'm not sure. I don't understand >> relfection concepts well enough and the Py->Java (callback) thing seems >> to suggest I should be fine since the original eventlistener hasn't been >> garbage collected yet. If you have any insight that would be great. >> >> Error: >> py4j.protocol.Py4JJavaError: An error occurred while calling >> t.removeEventListener. >> : py4j.Py4JException: An exception was raised by the Python Proxy. >> Return Message: x >> at py4j.Protocol.getReturnValue(Protocol.java:417) >> at >> py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) >> at com.sun.proxy.$Proxy0.equals(Unknown Source) >> at java.util.Vector.indexOf(Vector.java:404) >> at java.util.Vector.indexOf(Vector.java:378) >> at java.util.Vector.removeElement(Vector.java:637) >> at java.util.Vector.remove(Vector.java:795) >> at >> pctelelog.EventOperatorThread.removeEventListener(EventOperatorThread.java:20) >> at pctelelog.ServerThread.removeEventListener(ServerThread.java:16) >> at pctelelog.Launcher.removeEventListener(Launcher.java:17) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) >> >> This code is a stripped down version of the development version but both >> are generating the same error. >> >> package pctelelog; >> >> public class Event { >> public String testData = "test"; >> } >> >> === >> >> package pctelelog; >> >> public interface EventListener { >> public void onEvent(Event event); >> } >> >> === >> >> package pctelelog; >> >> import java.util.Vector; >> >> public class EventOperatorThread extends Thread { >> >> private Vector<EventListener> m_listeners = new >> Vector<EventListener>(); >> >> public void run() { >> while(true) {} >> } >> >> public synchronized void addEventListener(EventListener listener) { >> System.out.println("ADD"); >> m_listeners.add(listener); >> } >> >> public synchronized void removeEventListener(EventListener listener) { >> System.out.println("REMOVE"); >> m_listeners.remove(listener); >> } >> } >> >> === >> >> package pctelelog; >> >> public class ServerThread extends Thread { >> >> private EventOperatorThread m_operator = new EventOperatorThread(); >> >> public void run() { >> m_operator.start(); >> while(true) {} >> } >> >> public synchronized void addEventListener(EventListener listener) { >> m_operator.addEventListener(listener); >> } >> public synchronized void removeEventListener(EventListener listener) { >> m_operator.removeEventListener(listener); >> } >> >> } >> >> === >> >> package pctelelog; >> >> import py4j.GatewayServer; >> >> public class Launcher { >> private ServerThread m_server = new ServerThread(); >> >> public Launcher() { >> m_server.start(); >> System.out.println("Server started."); >> } >> >> public void addEventListener(EventListener listener) { >> m_server.addEventListener(listener); >> } >> public void removeEventListener(EventListener listener) { >> m_server.removeEventListener(listener); >> } >> >> public static void main(String[] args) { >> GatewayServer gateway = new GatewayServer(new Launcher()); >> gateway.start(); >> } >> } >> >> === >> >> from py4j.java_gateway import JavaGateway, GatewayClient >> >> class EventListener(object): >> >> def onEvent(self, event): >> print event.testData; >> >> class Java: >> implements = ['pctelelog.EventListener'] >> >> class Launcher: >> >> def __init__(self): >> self.__gateway = JavaGateway(start_callback_server=True) >> listener = EventListener() >> self.__gateway.entry_point.addEventListener(listener) >> self.__gateway.entry_point.removeEventListener(listener) >> >> if __name__ == '__main__': >> Launcher() >> pass >> >> >> ------------------------------------------------------------------------------ >> Is your legacy SCM system holding you back? Join Perforce May 7 to find out: >> • 3 signs your SCM is hindering your productivity >> • Requirements for releasing software faster >> • Expert tips and advice for migrating your SCM now >> http://p.sf.net/sfu/perforce >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Barthelemy D. <bar...@in...> - 2014-05-07 11:54:42
|
Hi! Thanks for using Py4J! I'll try to look at this issue more deeply during the weekend, but from the stack trace, it seems the Java side is sending a method call to the Python side and the Python side is replying with an exception: Error: py4j.protocol.Py4JJavaError: An error occurred while calling t.removeEventListener. : py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: x Also, from the stack trace, it appears that when deleting the listener from the Java vector, the vector calls the "equals" method on the listener. This is the first time I have to deal with this scenario and I believe the equals method is delegated to the python side. Because it is not implemented, I believe this may be the cause of failure. A workaround might be to try to implement an "equals" method in your Python listener. Do you have logging enabled on the Python side? Any stack trace visible there? Btw, you should subscribe to the mailing list, it would be easier to manage the replies :-) Bart On Tue, May 6, 2014 at 7:58 PM, Jeremy <ken...@gm...> wrote: > So I'm trying to use Py4j to let a UI talk to a Java server. The java > server uses 3 threads (entry-point, server socket, client-event > dispatch). The python UI registers an event call back listener and that > listener eventually gets dumped into a Vector. I had some initial > trouble getting the addEventListener() working but fixed it (somehow). > But now any calls to removeEventListener() don't work. > > My first guess was something to do with different instances of the > object when Vector does the lookup, but I'm not sure. I don't understand > relfection concepts well enough and the Py->Java (callback) thing seems > to suggest I should be fine since the original eventlistener hasn't been > garbage collected yet. If you have any insight that would be great. > > Error: > py4j.protocol.Py4JJavaError: An error occurred while calling > t.removeEventListener. > : py4j.Py4JException: An exception was raised by the Python Proxy. > Return Message: x > at py4j.Protocol.getReturnValue(Protocol.java:417) > at > py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) > at com.sun.proxy.$Proxy0.equals(Unknown Source) > at java.util.Vector.indexOf(Vector.java:404) > at java.util.Vector.indexOf(Vector.java:378) > at java.util.Vector.removeElement(Vector.java:637) > at java.util.Vector.remove(Vector.java:795) > at > pctelelog.EventOperatorThread.removeEventListener(EventOperatorThread.java:20) > at pctelelog.ServerThread.removeEventListener(ServerThread.java:16) > at pctelelog.Launcher.removeEventListener(Launcher.java:17) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > > This code is a stripped down version of the development version but both > are generating the same error. > > package pctelelog; > > public class Event { > public String testData = "test"; > } > > === > > package pctelelog; > > public interface EventListener { > public void onEvent(Event event); > } > > === > > package pctelelog; > > import java.util.Vector; > > public class EventOperatorThread extends Thread { > > private Vector<EventListener> m_listeners = new > Vector<EventListener>(); > > public void run() { > while(true) {} > } > > public synchronized void addEventListener(EventListener listener) { > System.out.println("ADD"); > m_listeners.add(listener); > } > > public synchronized void removeEventListener(EventListener listener) { > System.out.println("REMOVE"); > m_listeners.remove(listener); > } > } > > === > > package pctelelog; > > public class ServerThread extends Thread { > > private EventOperatorThread m_operator = new EventOperatorThread(); > > public void run() { > m_operator.start(); > while(true) {} > } > > public synchronized void addEventListener(EventListener listener) { > m_operator.addEventListener(listener); > } > public synchronized void removeEventListener(EventListener listener) { > m_operator.removeEventListener(listener); > } > > } > > === > > package pctelelog; > > import py4j.GatewayServer; > > public class Launcher { > private ServerThread m_server = new ServerThread(); > > public Launcher() { > m_server.start(); > System.out.println("Server started."); > } > > public void addEventListener(EventListener listener) { > m_server.addEventListener(listener); > } > public void removeEventListener(EventListener listener) { > m_server.removeEventListener(listener); > } > > public static void main(String[] args) { > GatewayServer gateway = new GatewayServer(new Launcher()); > gateway.start(); > } > } > > === > > from py4j.java_gateway import JavaGateway, GatewayClient > > class EventListener(object): > > def onEvent(self, event): > print event.testData; > > class Java: > implements = ['pctelelog.EventListener'] > > class Launcher: > > def __init__(self): > self.__gateway = JavaGateway(start_callback_server=True) > listener = EventListener() > self.__gateway.entry_point.addEventListener(listener) > self.__gateway.entry_point.removeEventListener(listener) > > if __name__ == '__main__': > Launcher() > pass > > > ------------------------------------------------------------------------------ > Is your legacy SCM system holding you back? Join Perforce May 7 to find out: > • 3 signs your SCM is hindering your productivity > • Requirements for releasing software faster > • Expert tips and advice for migrating your SCM now > http://p.sf.net/sfu/perforce > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |
From: Jeremy <ken...@gm...> - 2014-05-06 23:58:43
|
So I'm trying to use Py4j to let a UI talk to a Java server. The java server uses 3 threads (entry-point, server socket, client-event dispatch). The python UI registers an event call back listener and that listener eventually gets dumped into a Vector. I had some initial trouble getting the addEventListener() working but fixed it (somehow). But now any calls to removeEventListener() don't work. My first guess was something to do with different instances of the object when Vector does the lookup, but I'm not sure. I don't understand relfection concepts well enough and the Py->Java (callback) thing seems to suggest I should be fine since the original eventlistener hasn't been garbage collected yet. If you have any insight that would be great. Error: py4j.protocol.Py4JJavaError: An error occurred while calling t.removeEventListener. : py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: x at py4j.Protocol.getReturnValue(Protocol.java:417) at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:113) at com.sun.proxy.$Proxy0.equals(Unknown Source) at java.util.Vector.indexOf(Vector.java:404) at java.util.Vector.indexOf(Vector.java:378) at java.util.Vector.removeElement(Vector.java:637) at java.util.Vector.remove(Vector.java:795) at pctelelog.EventOperatorThread.removeEventListener(EventOperatorThread.java:20) at pctelelog.ServerThread.removeEventListener(ServerThread.java:16) at pctelelog.Launcher.removeEventListener(Launcher.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) This code is a stripped down version of the development version but both are generating the same error. package pctelelog; public class Event { public String testData = "test"; } === package pctelelog; public interface EventListener { public void onEvent(Event event); } === package pctelelog; import java.util.Vector; public class EventOperatorThread extends Thread { private Vector<EventListener> m_listeners = new Vector<EventListener>(); public void run() { while(true) {} } public synchronized void addEventListener(EventListener listener) { System.out.println("ADD"); m_listeners.add(listener); } public synchronized void removeEventListener(EventListener listener) { System.out.println("REMOVE"); m_listeners.remove(listener); } } === package pctelelog; public class ServerThread extends Thread { private EventOperatorThread m_operator = new EventOperatorThread(); public void run() { m_operator.start(); while(true) {} } public synchronized void addEventListener(EventListener listener) { m_operator.addEventListener(listener); } public synchronized void removeEventListener(EventListener listener) { m_operator.removeEventListener(listener); } } === package pctelelog; import py4j.GatewayServer; public class Launcher { private ServerThread m_server = new ServerThread(); public Launcher() { m_server.start(); System.out.println("Server started."); } public void addEventListener(EventListener listener) { m_server.addEventListener(listener); } public void removeEventListener(EventListener listener) { m_server.removeEventListener(listener); } public static void main(String[] args) { GatewayServer gateway = new GatewayServer(new Launcher()); gateway.start(); } } === from py4j.java_gateway import JavaGateway, GatewayClient class EventListener(object): def onEvent(self, event): print event.testData; class Java: implements = ['pctelelog.EventListener'] class Launcher: def __init__(self): self.__gateway = JavaGateway(start_callback_server=True) listener = EventListener() self.__gateway.entry_point.addEventListener(listener) self.__gateway.entry_point.removeEventListener(listener) if __name__ == '__main__': Launcher() pass |
From: Barthelemy D. <bar...@in...> - 2014-03-18 23:38:34
|
Hi, enumerations are supported in py4j like regular classes. Assuming the following Enum: package py4j; public enum MyEnum { Mon, Tue, Wed, Thu, Fri, Sat, Sun; } Here is some working code: In [1]: from py4j.java_gateway import JavaGateway In [2]: gateway = JavaGateway() In [3]: my_enum = gateway.jvm.py4j.MyEnum In [4]: my_enum.Sat Out[4]: JavaObject id=o0 In [5]: my_enum.Sat == my_enum.Sat Out[5]: True In [6]: my_enum.Sat == my_enum.Sun Out[6]: False In [7]: sat = my_enum.Sat In [8]: sat == my_enum.Sat Out[8]: True In [9]: sat == my_enum.Sun Out[9]: False Does that make sense? Barthélémy On Tue, Mar 18, 2014 at 2:39 PM, He-chien Tsai <dep...@gm...> wrote: > Sorry for duplicated, I forget adding subject. > > It seems that 'A==B' didn't work at python side. > for example, > > public enum WeekDayEnum { Mon, Tue, Wed, Thu, Fri, Sat, Sun } > > I want to check this "gateway.jvm.WeekDayEnum.Fri == day" but iit doesn't > work > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and their > applications. Written by three acclaimed leaders in the field, > this first edition is now available. Download your free book today! > http://p.sf.net/sfu/13534_NeoTech > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: He-chien T. <dep...@gm...> - 2014-03-18 18:39:44
|
Sorry for duplicated, I forget adding subject. It seems that 'A==B' didn't work at python side. for example, public enum WeekDayEnum { Mon, Tue, Wed, Thu, Fri, Sat, Sun } I want to check this "gateway.jvm.WeekDayEnum.Fri == day" but iit doesn't work |
From: He-chien T. <dep...@gm...> - 2014-03-18 18:36:42
|
It seems that 'A==B' didn't work at python side. for example, public enum WeekDayEnum { Mon, Tue, Wed, Thu, Fri, Sat, Sun } I want to check this "gateway.jvm.WeekDayEnum.Fri == day" |
From: Kieran L. <kl...@ir...> - 2014-01-23 05:38:12
|
Thanks for the reply Barthélémy. I can confirm that now I too have got it working with basic proof of concept code running Java 7 and Python 3.2. Thank you for providing a good project that is well documented. The website still mentions Java 6 only though so I'm guessing you haven't update this page yet (http://py4j.sourceforge.net/download.html) Regards, Kieran -----Original Message----- From: Barthelemy Dagenais [mailto:bar...@in...] Sent: Friday, 10 January 2014 8:52 PM To: Support and Comments about Py4J Subject: Re: [Py4j-users] Will Py4J work with Java 7.4 Hi, Thanks for your interest in Py4J! Py4J works with Java 7. It is actually tested against openjdk 7 by travis-ci on each push. I'll update the requirements on the website to make it clearer. Barthélémy On Fri, Jan 10, 2014 at 1:11 AM, Kieran Love <kl...@ir...> wrote: > Hello, > > > Will Py4J work with Java 7.4 or am I stuck on using it with Java 6 only? > > > > Thanks in advance, > > Kieran > > ********************************************************************** > ************************ > Important Note > This email (including any attachments) contains information which is > confidential and may be subject to legal privilege. If you are not > the intended recipient you must not use, distribute or copy this > email. If you have received this email in error please notify the > sender immediately and delete this email. Any views expressed in this > email are not necessarily the views of IRESS Limited. > > It is the duty of the recipient to virus scan and otherwise test the > information provided before loading onto any computer system. > IRESS Limited does not warrant that the information is free of a virus > or any other defect or error. > ********************************************************************** > ************************ > > > ---------------------------------------------------------------------- > -------- CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical > Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg. > clktrk _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk _______________________________________________ Py4j-users mailing list Py4...@li... https://lists.sourceforge.net/lists/listinfo/py4j-users ********************************************************************************************** Important Note This email (including any attachments) contains information which is confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, distribute or copy this email. If you have received this email in error please notify the sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Limited. It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system. IRESS Limited does not warrant that the information is free of a virus or any other defect or error. ********************************************************************************************** |
From: Barthelemy D. <bar...@in...> - 2014-01-10 09:52:10
|
Hi, Thanks for your interest in Py4J! Py4J works with Java 7. It is actually tested against openjdk 7 by travis-ci on each push. I'll update the requirements on the website to make it clearer. Barthélémy On Fri, Jan 10, 2014 at 1:11 AM, Kieran Love <kl...@ir...> wrote: > Hello, > > > Will Py4J work with Java 7.4 or am I stuck on using it with Java 6 only? > > > > Thanks in advance, > > Kieran > > ********************************************************************************************** > Important Note > This email (including any attachments) contains information which is > confidential and may be subject to legal privilege. If you are not the > intended recipient you must not use, distribute or copy this email. If you > have received this email in error please notify the > sender immediately and delete this email. Any views expressed in this email > are not necessarily the views of IRESS Limited. > > It is the duty of the recipient to virus scan and otherwise test the > information provided before loading onto any computer system. > IRESS Limited does not warrant that the information is free of a virus or > any other defect or error. > ********************************************************************************************** > > > ------------------------------------------------------------------------------ > CenturyLink Cloud: The Leader in Enterprise Cloud Services. > Learn Why More Businesses Are Choosing CenturyLink Cloud For > Critical Workloads, Development Environments & Everything In Between. > Get a Quote or Start a Free Trial Today. > http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Kieran L. <kl...@ir...> - 2014-01-10 06:23:49
|
Hello, Will Py4J work with Java 7.4 or am I stuck on using it with Java 6 only? Thanks in advance, Kieran ********************************************************************************************** Important Note This email (including any attachments) contains information which is confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, distribute or copy this email. If you have received this email in error please notify the sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Limited. It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system. IRESS Limited does not warrant that the information is free of a virus or any other defect or error. ********************************************************************************************** |
From: Barthelemy D. <bar...@in...> - 2013-12-26 16:21:42
|
Hi, this is a minor release featuring the long awaited availability of Py4J on maven central repository. This release includes the following new features: - Fixed a bug in type inference when interface hierarchy is deeper than abstract class hierarchy. - Added a utility method is_instance_of in py4j.java_gateway to determine if a JavaObject is an instance of a type. - Released Py4J in central Maven repository (https://oss.sonatype.org/content/groups/public/net/sf/py4j/py4j/0.8.1/). I'm still waiting for a final confirmation from sonatype before they enable the automatic syncing of Py4J maven releases. Installing Py4J is one pip away: pip install py4j Again, feel free to contact me or to write a feature request on GitHub! Cheers, Barthélémy |
From: Barthelemy D. <bar...@in...> - 2013-09-07 10:13:16
|
Hi Chris, glad you could fix it! I was replying with exactly this solution when I saw you had sent a follow up. Barthélémy On Sat, Sep 7, 2013 at 1:53 AM, Chris Akins <chr...@gm...> wrote: > Hi, all. > Issue's resolved. I had to create the array of HGHandles that the > constructor was expecting by hand, so > Java: > x=new HGValueLink("asdf", h1, h2) > > became Python: > a=new_array(HGHandle, 2); > a[0]=h1; > a[1]=h2; > x=gateway.jvm.org.hypergraphdb.hGValueLink("asdf",a) > > Thanks for your hard work. > > -Chris > > > On Sat, Sep 7, 2013 at 12:16 AM, Chris Akins <chr...@gm...> wrote: >> >> Hi all. >> >> I'm trying to implement this code in Python: (from >> http://www.hypergraphdb.org/learn?page=IntroStoreData&project=hypergraphdb >> at the bottom, modified so I don't have to implement a class on the Java >> side) >> >> bookHandle = graph.add("asdf") >> priceHandle = graph.add(9.95) >> link = new gateway.jvm.org.hypergraphdb.HGValueLink("price", bookHandle, >> priceHandle) >> >> >> >> >> >> The problem is that in the Python code, the call to graph.add() from the >> Python side is yielding an object of type >> WeakHandle that implements HGLiveHandle, and HGValueLink only accepts >> HGHandle[] in its arguments. The end result is >> >> >> >> that the java side throws an exception saying that a HGValueLink >> constructor doesn't exist that takes >> [String, handle.WeakHandle, handle.WeakHandle]. >> >> (Relevant javadocs at >> http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HGValueLink.html, >> >> >> >> http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HyperGraph.html, >> >> http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/handle/HGLiveHandle.html >> ) >> >> >> >> In the linked example the two handles are declared as HGHandle when >> they're instantiated, so there's no problem when the method call does >> typechecking. >> >> >> >> It seems to me, then, that the easiest way to rectify this is to use some >> facility of the Gateway to re-cast the object returned from graph.add() as >> HGHandle, and then just pass that the the HGValueLink constructor as it >> wants. >> >> >> >> Can I do that from the gateway as it exists, or do I have to add a method >> to my server code to cast it? Am I missing an easier and more obvious >> solution in my Java inexperience? >> >> >> >> Thanks, >> Chris >> > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |
From: Chris A. <chr...@gm...> - 2013-09-07 05:53:46
|
Hi, all. Issue's resolved. I had to create the array of HGHandles that the constructor was expecting by hand, so Java: x=new HGValueLink("asdf", h1, h2) became Python: a=new_array(HGHandle, 2); a[0]=h1; a[1]=h2; x=gateway.jvm.org.hypergraphdb.hGValueLink("asdf",a) Thanks for your hard work. -Chris On Sat, Sep 7, 2013 at 12:16 AM, Chris Akins <chr...@gm...> wrote: > Hi all. > > I'm trying to implement this code in Python: (from > http://www.hypergraphdb.org/learn?page=IntroStoreData&project=hypergraphdbat the bottom, modified so I don't have to implement a class on the Java > side) > > bookHandle = graph.add("asdf") > priceHandle = graph.add(9.95) > link = new gateway.jvm.org.hypergraphdb.HGValueLink("price", bookHandle, > priceHandle) > > > > The problem is that in the Python code, the call to graph.add() from the Python side is yielding an object of type > WeakHandle that implements HGLiveHandle, and HGValueLink only accepts HGHandle[] in its arguments. The end result is > > > that the java side throws an exception saying that a HGValueLink constructor doesn't exist that takes > [String, handle.WeakHandle, handle.WeakHandle]. > > (Relevant javadocs at http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HGValueLink.html, > > http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HyperGraph.html, > http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/handle/HGLiveHandle.html ) > > In the linked example the two handles are declared as HGHandle when they're instantiated, so there's no problem when the method call does typechecking. > > It seems to me, then, that the easiest way to rectify this is to use some facility of the Gateway to re-cast the object returned from graph.add() as HGHandle, and then just pass that the the HGValueLink constructor as it wants. > > Can I do that from the gateway as it exists, or do I have to add a method to my server code to cast it? Am I missing an easier and more obvious solution in my Java inexperience? > > Thanks, > Chris > > |