本文整理汇总了Python中PyQt4.QtCore.QThreadPool.globalInstance方法的典型用法代码示例。如果您正苦于以下问题:Python QThreadPool.globalInstance方法的具体用法?Python QThreadPool.globalInstance怎么用?Python QThreadPool.globalInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QThreadPool
的用法示例。
在下文中一共展示了QThreadPool.globalInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_send_status_clicked
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def on_send_status_clicked(self):
status = self.ui.status.toPlainText().__str__()
self.ui.status.clear()
self.ui.status.setReadOnly(True)
sender = SenderCommand(self.client, status)
sender.posted.connect(self.status_posted)
command_processor = CommandProcessor(sender)
QThreadPool.globalInstance().start(command_processor)
示例2: process
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def process(self, caller, func, *args, **kwargs):
# Add the caller
self._add_listener(caller)
# Generate worker
self._worker = Worker(func, *args, **kwargs)
self._worker.signals.finished.connect(self.on_finished)
self._worker.signals.error.connect(self.on_error)
QThreadPool.globalInstance().start(self._worker)
示例3: run_worker
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def run_worker(self, task, callback):
"""Runs a task in another thread.
The `task` must be an object that implements a `run()`
method. Completion is notified to the given `callback` function.
"""
worker = Worker(task)
worker.finished.connect(callback)
QThreadPool.globalInstance().start(worker)
示例4: query
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def query(self, key):
"""Emit query."""
collect = Collect(
list(map(lambda a: a.engine, filter(Group.selected, self.output_areas))),
lambda r: self.record(key, r)
)
QThreadPool.globalInstance().start(collect)
#for engine in self.engines:
#QThreadPool.globalInstance().start(
#Runnable(lambda: engine.query(key), args=(object,)))
async_actions(map(lambda e: partial(e.query, key), self.engines))
示例5: test_that_process_states_emits_row_processed_signal_after_each_row
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def test_that_process_states_emits_row_processed_signal_after_each_row(self):
self.batch_process_runner.row_processed_signal = mock.MagicMock()
self.batch_process_runner.row_failed_signal = mock.MagicMock()
self.batch_process_runner.process_states(self.states, False, OutputMode.Both, False, '')
QThreadPool.globalInstance().waitForDone()
self.assertEqual(self.batch_process_runner.row_processed_signal.emit.call_count, 3)
self.batch_process_runner.row_processed_signal.emit.assert_any_call(0, [], [])
self.batch_process_runner.row_processed_signal.emit.assert_any_call(1, [], [])
self.batch_process_runner.row_processed_signal.emit.assert_any_call(2, [], [])
self.assertEqual(self.batch_process_runner.row_failed_signal.emit.call_count, 0)
示例6: test_that_load_workspaces_emits_row_processed_signal_after_each_row
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def test_that_load_workspaces_emits_row_processed_signal_after_each_row(self):
self.batch_process_runner.row_processed_signal = mock.MagicMock()
self.batch_process_runner.row_failed_signal = mock.MagicMock()
self.batch_process_runner.load_workspaces(self.states)
QThreadPool.globalInstance().waitForDone()
self.assertEqual(self.batch_process_runner.row_processed_signal.emit.call_count, 3)
self.batch_process_runner.row_processed_signal.emit.assert_any_call(0, [], [])
self.batch_process_runner.row_processed_signal.emit.assert_any_call(1, [], [])
self.batch_process_runner.row_processed_signal.emit.assert_any_call(2, [], [])
self.assertEqual(self.batch_process_runner.row_failed_signal.emit.call_count, 0)
示例7: record
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def record(self, key, responses):
"""Record in background."""
if not self.recorder is None:
runnable = Runnable(lambda: self.recorder.add(
#word=s.word,
#pron=s.phonetic_symbol,
#trans='\n'.join(s.custom_translations),
#time=datetime.now()
key=key,
responses=responses
))
runnable.finished.connect(self.recorded)
QThreadPool.globalInstance().start(runnable)
示例8: push_to_website
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def push_to_website(payload):
time = payload[SENSOR_TIMESTAMP]["val"]
for key in payload:
category = payload[key]["cat"]
value = payload[key]["val"]
if category == CAT_NONE:
continue
api = WebsiteAPI()
api.set_password(WEB_PASSWORD)
api.set_host(WEB_HOST)
api.set_data(category, key, value, time)
QThreadPool.globalInstance().start(api)
示例9: __init__
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def __init__(self, func=None, args=(), kwargs={}, thread=None,
threadPool=None, parent=None):
QObject.__init__(self, parent)
self.func = func
self._args = args
self._kwargs = kwargs
self.threadPool = None
self._connected = True
self._cancelRequested = False
self._started = False
self._cancelled = False
if thread is not None:
self.moveToThread(thread)
else:
if threadPool is None:
threadPool = QThreadPool.globalInstance()
self.threadPool = threadPool
self._runnable = _RunnableAsyncCall(self)
self.threadPool.start(self._runnable)
self._connected = False
return
self.connect(self, SIGNAL("_async_start()"), self.execute,
Qt.QueuedConnection)
示例10: __init__
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def __init__(self, parent=None, threadPool=None):
QObject.__init__(self, parent)
if threadPool is None:
threadPool = QThreadPool.globalInstance()
self._threadPool = threadPool
self._depot_thread = None
self._futures = []
self._shutdown = False
self._state_lock = threading.Lock()
示例11: login
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def login(self):
assert self.settings.username,\
'Invalid username: %s' % self.settings.username
def inner():
try:
self.recorder = ThreadSafeRecorder(Recorder(
username=self.settings.username,
password=self.settings.password,
deck=self.settings.deck
))
except:
return False
else:
return True
runnable = Runnable(inner)
runnable.finished.connect(self.logined)
QThreadPool.globalInstance().start(runnable)
示例12: test_that_process_states_calls_batch_reduce_for_each_row
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def test_that_process_states_calls_batch_reduce_for_each_row(self):
self.batch_process_runner.process_states(self.states, False, OutputMode.Both, False, '')
QThreadPool.globalInstance().waitForDone()
self.assertEqual(self.sans_batch_instance.call_count, 3)
示例13: deffer_to_thread
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def deffer_to_thread(self, cb, *args, **kwargs):
args = (self, ) + args
thread = Thread(self, cb, *args, **kwargs)
QThreadPool.globalInstance().start(thread)
示例14: start
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
def start(self):
QThreadPool.globalInstance().start(self.worker)
示例15: open_file_browser
# 需要导入模块: from PyQt4.QtCore import QThreadPool [as 别名]
# 或者: from PyQt4.QtCore.QThreadPool import globalInstance [as 别名]
# q.run()
# logger.log(" : ".join[mname,tid,"result",res])
### gui based ###
def open_file_browser():
""
path = QtGui.QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Select config file:"),"*.ini")
# if path:
# self.database = path # To make possible cancel the FileDialog and continue loading a predefined db
# self.openDBFile()
return path
# @log
# def open_window():
# ""
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mon = QThreadPool.globalInstance()
print mon.activeThreadCount()
sys.exit(app.exec_())