예제 #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
예제 #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()
예제 #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()
예제 #4
0
파일: _jpackage.py 프로젝트: baztian/jpype
    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
예제 #5
0
파일: _core.py 프로젝트: JiadaoZ22/NLP
def attachThreadToJVM():
    _jpype.attachThreadToJVM()
예제 #6
0
파일: _refdaemon.py 프로젝트: 736907871/zyl
 def _run():
     _jpype.attachThreadToJVM()
     _jpype.startReferenceQueue(0)
예제 #7
0
def attachThreadToJVM() :
    _jpype.attachThreadToJVM()
예제 #8
0
 def testDetachThread(self):
     self.assertTrue(_jpype.isThreadAttachedToJVM())
     _jpype.detachThreadFromJVM()
     self.assertFalse(_jpype.isThreadAttachedToJVM())
     _jpype.attachThreadToJVM()
예제 #9
0
 def testAttachThread(self):
     _jpype.fault("PyJPModule_attachThread")
     with self.assertRaisesRegex(SystemError, "fault"):
         _jpype.attachThreadToJVM()
예제 #10
0
    def _run():
        _jpype.attachThreadToJVM()
        _jpype.startReferenceQueue(0)

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

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