Re: [Py4j-users] Exception when printing a returned List<String> object
Status: Beta
Brought to you by:
barthe
From: Barthelemy D. <bar...@in...> - 2014-12-23 13:15:12
|
Hi, When printing the list, Py4J retrieves an Iterator and wraps it with py4j.java_collections.JavaIterator. It then cycles through the list with the iterator. JavaIterator should catch the NoSuchElementException and raise instead a StopIteration. Because it does not, I suspect something is messing with the automated wrapping of collections. could you do: iter = ret.iterator() print(type(iter)) This should print something like <class 'py4j.java_collections.JavaIterator'> Thanks, Barthelemy On Tue, Dec 23, 2014 at 6:10 AM, <hg...@it...> wrote: > Hi, > > > The method in my gateway server will return a List<String> object. When I > access it in my python client code, the server has exception and then > closed. The following is part of the exceptions > > > > > ▒Q▒G▒▒ 23, 2014 5:18:14 ▒U▒▒ py4j.reflection.MethodInvoker invoke > ĵ▒i: Exception occurred in client code. > java.lang.reflect.InvocationTargetException > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:483) > at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231) > at > py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379) > at py4j.Gateway.invoke(Gateway.java:259) > 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) > Caused by: java.util.NoSuchElementException > at java.util.AbstractList$Itr.next(AbstractList.java:364) > ... 11 more > > What I do in client code is the following: > >>>>ret = gateway.entry_point.getMyStringList(inputStr) # it's ok to run >>>> this line >>>>print ret # when running to this line, the server raised exception > > > Below is the method in server side: > > public List<String> getMyStringList(String input) throws IOException { > List<String> strList = new ArrayList<String>(); > strList = segmenter.segmentString(input); // this is some 3rd party > API for string tokenization and has been tested OK in console, the return > object is List<String> > > return strList; > } > > It's OK to access "ret" using indices and len(), but when I just type "ret" > or "print ret", then it would display the content of "ret", but then the > server poped Exception and stopped. What would be the problemt? Thanks for > any help! > > > > Frank Yang > > > 本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 > This email may contain confidential information. Please do not use or > disclose it in any way and delete it if you are not the intended recipient. > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming! The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |