Implement Runnable on python side

442 views
Skip to first unread message

Eugene Chekanskiy

unread,
Oct 1, 2017, 5:01:56 PM10/1/17
to Jep Project
Is it possible to implement Runnable on python side?
I am trying following code

import threading
import jep
from jep import jproxy


from java.lang import Thread


print("main ident:", threading.get_ident())


class RunnableImpl(object):
 
def run(self):
 
print("thread ident:", threading.get_ident())


myrunnbale
= jproxy(RunnableImpl(), ['java.lang.Runnable'])
t
= Thread(myrunnbale)
t
.start()
t
.join()

but got following exception:

main ident: 52228
Exception in thread "Thread-1" java.lang.reflect.UndeclaredThrowableException
        at com
.sun.proxy.$Proxy0.run(Unknown Source)
        at java
.lang.Thread.run(Thread.java:748)
Caused by: jep.JepException: Invalid thread access.
        at jep
.Jep.isValidThread(Jep.java:466)
        at jep
.InvocationHandler.invoke(InvocationHandler.java:123)
       
... 2 more

It is supported use-case?

Eugene Chekanskiy

unread,
Oct 2, 2017, 4:07:22 AM10/2/17
to Jep Project
It is not. Reading jep javadoc:
* In general, methods called on a Jep instance must be called from the same
* thread that created the instance. To maintain stability, avoid having two Jep
* instances running on the same thread at the same time.
понедельник, 2 октября 2017 г., 0:01:56 UTC+3 пользователь Eugene Chekanskiy написал:

Ben Steffensmeier

unread,
Oct 2, 2017, 12:02:50 PM10/2/17
to Jep Project
You can implement Runnable but as you saw you cannot use that Runnable on a different thread. Objects created with jproxy can only be used on the thread where they were created. When you call the run method it will access python through the Jep instance where it was created and each Jep instance is only valid on one thread.

Ben
Reply all
Reply to author
Forward
0 new messages