Exemple #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
Exemple #2
0
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()
Exemple #3
0
    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()
Exemple #4
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
Exemple #5
0
def attachThreadToJVM():
    _jpype.attachThreadToJVM()
Exemple #6
0
 def _run():
     _jpype.attachThreadToJVM()
     _jpype.startReferenceQueue(0)
Exemple #7
0
def attachThreadToJVM() :
    _jpype.attachThreadToJVM()
Exemple #8
0
 def testDetachThread(self):
     self.assertTrue(_jpype.isThreadAttachedToJVM())
     _jpype.detachThreadFromJVM()
     self.assertFalse(_jpype.isThreadAttachedToJVM())
     _jpype.attachThreadToJVM()
Exemple #9
0
 def testAttachThread(self):
     _jpype.fault("PyJPModule_attachThread")
     with self.assertRaisesRegex(SystemError, "fault"):
         _jpype.attachThreadToJVM()
Exemple #10
0
    def _run():
        _jpype.attachThreadToJVM()
        _jpype.startReferenceQueue(0)

        threading.Thread(target=_run).start()
Exemple #11
0
    def _run():
        _jpype.attachThreadToJVM()
        _jpype.startReferenceQueue(0)

        threading.Thread(target=_run).start()
Exemple #12
0
    def _run() :
    	_jpype.attachThreadToJVM()
        _jpype.startReferenceQueue(0)
        
	thread.start_new_thread(_run, tuple())