Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
def isThreadAttachedToJVM():
    """ Checks if a thread is attached to the JVM.

    Python automatically attaches threads when a Java method is called.
    This creates a resource in Java for the Python thread. This method
    can be used to check if a Python thread is currently attached so that
    it can be disconnected prior to thread termination to prevent leaks.

    Returns:
      True if the thread is attached to the JVM, False if the thread is
      not attached or the JVM is not running.
    """
    return _jpype.isThreadAttachedToJVM()
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def isThreadAttachedToJVM():
    return _jpype.isThreadAttachedToJVM()
Ejemplo n.º 5
0
def isThreadAttachedToJVM() :
    return _jpype.isThreadAttachedToJVM()
Ejemplo n.º 6
0
 def testIsThreadAttached(self):
     _jpype.fault("PyJPModule_isThreadAttached")
     with self.assertRaisesRegex(SystemError, "fault"):
         _jpype.isThreadAttachedToJVM()
Ejemplo n.º 7
0
 def testDetachThread(self):
     self.assertTrue(_jpype.isThreadAttachedToJVM())
     _jpype.detachThreadFromJVM()
     self.assertFalse(_jpype.isThreadAttachedToJVM())
     _jpype.attachThreadToJVM()