当前位置: 首页>>代码示例>>Python>>正文


Python QtCore.QMutex类代码示例

本文整理汇总了Python中PyQt5.QtCore.QMutex的典型用法代码示例。如果您正苦于以下问题:Python QMutex类的具体用法?Python QMutex怎么用?Python QMutex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QMutex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

 def run(self):
     mutex = QMutex()
     mutex.lock()
     try:
         if self.method == 'post':
             response = self.session.post(self.url, data=self.data, files=self.files)
         elif self.method == 'get':
             response = self.session.get(self.url)
         elif self.method == 'delete':
             response = self.session.delete(self.url)
         else:
             raise Exception('不正确的方法')
         if response.status_code >= 300:
             try:
                 data = response.json()
                 if 'non_field_errors' in data:
                     error_message = data['non_field_errors']
                 else:
                     error_message = data.get('error', '未知错误')
                 message = '网络请求错误,错误码为{},原因为{}'.format(response.status_code, error_message)
                 self.failed.emit(message)
             except:
                 print(response.text)
         else:
             data = response.json()
             self.success.emit(data)
     except requests.Timeout as error:
         self.failed.emit('网络请求错误,超时,请检查网络连接')
     except BaseException as error:
         print('BaseException'.format(error))
         self.failed.emit(str(error.args))
     finally:
         mutex.unlock()
         self.deleteLater()
开发者ID:rui19921122,项目名称:MeetingsDesktop_v2,代码行数:34,代码来源:requests.py

示例2: __init__

 def __init__(self, weboob, parent=None):
     QObject.__init__(self, parent)
     self.weboob = weboob
     self.weboob.callbacks['login'] = self.callback(self.LoginRequest)
     self.mutex = QMutex()
     self.requests = []
     self.new_request.connect(self.do_request)
开发者ID:ffourcot,项目名称:weboob,代码行数:7,代码来源:qt.py

示例3: __init__

 def __init__(self, weboob, parent=None):
     super(QCallbacksManager, self).__init__(parent)
     self.weboob = weboob
     self.weboob.requests.register('login', self.callback(self.LoginRequest))
     self.mutex = QMutex()
     self.requests = []
     self.new_request.connect(self.do_request)
开发者ID:P4ncake,项目名称:weboob,代码行数:7,代码来源:qt.py

示例4: Evaluate

class Evaluate(QThread):
    """Thread used to insolate calculation process in entities (stream, project
    and equipment, so gui can response while calculation is in process"""
    def __init__(self, parent=None):
        super(Evaluate, self).__init__(parent)
        self.mutex = QMutex()

    def start(self, entity, kwargs):
        self.entity = entity
        self.kwargs = kwargs
        QThread.start(self)

    def run(self):
        self.mutex.lock()
        self.entity(**self.kwargs)
        self.mutex.unlock()
开发者ID:ChEsolve,项目名称:pychemqt,代码行数:16,代码来源:thread.py

示例5: __init__

 def __init__(self, interval, project, vcs, parent=None):
     """
     Constructor
     
     @param interval new interval in seconds (integer)
     @param project reference to the project object (Project)
     @param vcs reference to the version control object
     @param parent reference to the parent object (QObject)
     """
     super(VcsStatusMonitorThread, self).__init__(parent)
     self.setObjectName("VcsStatusMonitorThread")
     
     self.setTerminationEnabled(True)
     
     self.projectDir = project.getProjectPath()
     self.project = project
     self.vcs = vcs
     
     self.interval = interval
     self.autoUpdate = False
     
     self.statusList = []
     self.reportedStates = {}
     self.shouldUpdate = False
     
     self.monitorMutex = QMutex()
     self.monitorCondition = QWaitCondition()
     self.__stopIt = False
开发者ID:testmana2,项目名称:test,代码行数:28,代码来源:StatusMonitorThread.py

示例6: __init__

    def __init__(self, parent=None):
        super(FortuneThread, self).__init__(parent)

        self.quit = False
        self.hostName = ''
        self.cond = QWaitCondition()
        self.mutex = QMutex()
        self.port = 0
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:8,代码来源:blockingfortuneclient.py

示例7: __init__

    def __init__(self, socket):
        super(PugdebugServerConnection, self).__init__()

        self.socket = socket

        self.mutex = QMutex()

        self.parser = PugdebugMessageParser()
开发者ID:mbarbon,项目名称:pugdebug,代码行数:8,代码来源:server.py

示例8: __init__

 def __init__(self, plugin_id, address, socket):
     QThread.__init__(self)
     self.plugin_id = plugin_id
     self.address = address
     self.udp_socket = socket
     self.finished.connect(self.quit)
     self.wait = QWaitCondition()
     self.mutex = QMutex()
开发者ID:n3rd-bugs,项目名称:weird-rtos,代码行数:8,代码来源:plugin_switch.py

示例9: __init__

    def __init__(self, parent=None):
        super(SyncAllThread, self).__init__(parent)
        print("thread initialized")
        self.mutex = QMutex()
        self.condition = QWaitCondition()

        self.restart = False
        self.abort = False
开发者ID:lighht,项目名称:pyonenote-old,代码行数:8,代码来源:database_manager.py

示例10: __init__

    def __init__(self, parent=None):
        super(FetchPage, self).__init__(parent)
        print('thread initialized')
        self.mutex = QMutex()
        self.condition = QWaitCondition()

        self.restart = False
        self.abort = False
开发者ID:lighht,项目名称:pyonenote-old,代码行数:8,代码来源:pages.py

示例11: Console

class Console(QObject):
    """
    The stream-like-object to redirect stream to Qt editor document
    """
    update = pyqtSignal(str)  # something is writen to console

    def __init__(self, editor, color=None, parent=None, waitCond=None):
        """
        :param editor: QTextBrowser or QPlainTextEditor etc.
        :param color: text color
        :return:
        """
        super(Console, self).__init__(parent)

        self.editor = editor
        self.color = color
        if self.color:
            self.editor.setTextColor(self.color)

        self.mutex = QMutex()
        self.waitCond = waitCond
        self.input = None

    def write(self, content):
        """
        Append to editor's document
        :param content:
        :return:
        """
        self.update.emit(content)

    def read(self):
        self.editor.setReadOnly(False)

        self.mutex.lock()
        self.waitCond.wait(self.mutex)
        self.mutex.unlock()
        return self.input

    def close(self):
        pass

    @pyqtSlot(str)
    def receivedInput(self, content):
        self.input = content
开发者ID:YieldNull,项目名称:cinter,代码行数:45,代码来源:window.py

示例12: __init__

    def __init__(self):
        super().__init__()

        self.queue = Queue()
        self.mutex = QMutex()

        self.enqueue_signal.connect(self.queue.put)
        self.done_signal.connect(self.mutex.unlock)

        self.start()
开发者ID:CenterForOpenScience,项目名称:osf-sync,代码行数:10,代码来源:tray.py

示例13: QCallbacksManager

class QCallbacksManager(QObject):
    class Request(object):
        def __init__(self):
            self.event = Event()
            self.answer = None

        def __call__(self):
            raise NotImplementedError()

    class LoginRequest(Request):
        def __init__(self, backend_name, value):
            super(QCallbacksManager.LoginRequest, self).__init__()
            self.backend_name = backend_name
            self.value = value

        def __call__(self):
            password, ok = QInputDialog.getText(None,
                '%s request' % self.value.label,
                'Please enter %s for %s' % (self.value.label,
                                            self.backend_name),
                                                QLineEdit.Password)
            return password

    new_request = Signal()

    def __init__(self, weboob, parent=None):
        super(QCallbacksManager, self).__init__(parent)
        self.weboob = weboob
        self.weboob.requests.register('login', self.callback(self.LoginRequest))
        self.mutex = QMutex()
        self.requests = []
        self.new_request.connect(self.do_request)

    def callback(self, klass):
        def cb(*args, **kwargs):
            return self.add_request(klass(*args, **kwargs))
        return cb

    @Slot()
    def do_request(self):
        self.mutex.lock()
        request = self.requests.pop()
        request.answer = request()
        request.event.set()
        self.mutex.unlock()

    def add_request(self, request):
        self.mutex.lock()
        self.requests.append(request)
        self.mutex.unlock()
        self.new_request.emit()
        request.event.wait()
        return request.answer
开发者ID:P4ncake,项目名称:weboob,代码行数:53,代码来源:qt.py

示例14: __init__

    def __init__(self, collection):
        """
        Constructor
        
        @param collection full pathname of the collection file (string)
        """
        super(HelpDocsInstaller, self).__init__()

        self.__abort = False
        self.__collection = collection
        self.__mutex = QMutex()
开发者ID:testmana2,项目名称:test,代码行数:11,代码来源:HelpDocsInstaller.py

示例15: FunctionThread

class FunctionThread(QThread):
    executed = pyqtSignal(dict)

    def __init__(self, parent=None):
        super(FunctionThread, self).__init__(parent)

        self.mutex = QMutex()
        
        self.function = None
        self.args = None
        self.kwargs = None
        self.returnValue = None

        self.finished.connect(self.on_thread_finished)

        self.done = True

    def __del__(self):
        self.wait()

    def execute(self, function, *args, **kwargs):
        locker = QMutexLocker(self.mutex)

        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.done = False

        self.start()

    def run(self):
        returnValue = self.function(*self.args, **self.kwargs)
        self.mutex.lock()
        self.returnValue = returnValue
        self.mutex.unlock()

    def on_thread_finished(self):
        result = {'returnValue': self.returnValue}
        self.done = True
        self.executed.emit(result)
开发者ID:johnymachine,项目名称:csv2db,代码行数:40,代码来源:database.py


注:本文中的PyQt5.QtCore.QMutex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。