def __getattribute__(self, n): try: return object.__getattribute__(self, n) except AttributeError as ex: if n.startswith("__"): raise ex # not found ... # perhaps it is a class? subname = "{0}.{1}".format(self.__name, n) if not _jpype.isStarted(): import warnings warnings.warn( "JVM not started yet, can not inspect JPackage contents") return n if not _jpype.isThreadAttachedToJVM(): _jpype.attachThreadToJVM() cc = _jpype.findClass(subname) if cc is None: # can only assume it is a sub-package then ... cc = JPackage(subname) else: cc = _jclass._getClassFor(cc) self.__setattr__(n, cc, True) return cc
def attachThreadToJVM(): """ Attaches a thread to the JVM. The function manually connects a thread to the JVM to allow access to Java objects and methods. JPype automatically attaches when a Java resource is used, so a call to this is usually not needed. Raises: RuntimeError: If the JVM is not running. """ _jpype.attachThreadToJVM()
def attach(): """ Attaches the current thread to the JVM as a user thread. User threads that are attached to the JVM will prevent the JVM from shutting down until the thread is terminated or detached. To convert a daemon thread to a main thread, the thread must first be detached. Raises: RuntimeError: If the JVM is not running. """ return _jpype.attachThreadToJVM()
def __getattribute__(self, n): try: return object.__getattribute__(self, n) except: # not found ... # perhaps it is a class? subname = "{0}.{1}".format(self.__name, n) if not _jpype.isStarted(): import warnings warnings.warn("JVM not started yet, can not inspect JPackage contents") return n if not _jpype.isThreadAttachedToJVM(): _jpype.attachThreadToJVM() cc = _jpype.findClass(subname) if cc is None: # can only assume it is a sub-package then ... cc = JPackage(subname) else: cc = _jclass._getClassFor(cc) self.__setattr__(n, cc, True) return cc
def attachThreadToJVM(): _jpype.attachThreadToJVM()
def _run(): _jpype.attachThreadToJVM() _jpype.startReferenceQueue(0)
def attachThreadToJVM() : _jpype.attachThreadToJVM()
def testDetachThread(self): self.assertTrue(_jpype.isThreadAttachedToJVM()) _jpype.detachThreadFromJVM() self.assertFalse(_jpype.isThreadAttachedToJVM()) _jpype.attachThreadToJVM()
def testAttachThread(self): _jpype.fault("PyJPModule_attachThread") with self.assertRaisesRegex(SystemError, "fault"): _jpype.attachThreadToJVM()
def _run(): _jpype.attachThreadToJVM() _jpype.startReferenceQueue(0) threading.Thread(target=_run).start()
def _run() : _jpype.attachThreadToJVM() _jpype.startReferenceQueue(0) thread.start_new_thread(_run, tuple())