本文整理汇总了Python中concurrent.futures.TimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python futures.TimeoutError方法的具体用法?Python futures.TimeoutError怎么用?Python futures.TimeoutError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类concurrent.futures
的用法示例。
在下文中一共展示了futures.TimeoutError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_query
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def _run_query(self, query):
query_job = self._client.query(query)
num_retries = 0
while True:
try:
iterator = query_job.result(timeout=300)
except TimeoutError as e:
logging.warning('Time out waiting for query: %s', query)
if num_retries < bigquery_util.BQ_NUM_RETRIES:
num_retries += 1
time.sleep(90)
else:
raise e
else:
break
result = []
for i in iterator:
result.append(str(i.values()[0]))
return result
示例2: _copy_to_flatten_table
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def _copy_to_flatten_table(self, output_table_id, cp_query):
job_config = bigquery.job.QueryJobConfig(destination=output_table_id)
query_job = self._client.query(cp_query, job_config=job_config)
num_retries = 0
while True:
try:
_ = query_job.result(timeout=600)
except TimeoutError as e:
logging.warning('Time out waiting for query: %s', cp_query)
if num_retries < bigquery_util.BQ_NUM_RETRIES:
num_retries += 1
time.sleep(90)
else:
logging.error('Copy to table query failed: %s', output_table_id)
raise e
else:
break
logging.info('Copy to table query was successful: %s', output_table_id)
示例3: start_suite
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def start_suite(self, suite: TestSuite) -> None:
"""Form list of tests for the Robot Framework test suite that are included in the TestRail test run.
If analysis depth of the run results is greater than zero, when first suite is launched
a list of 'testrailid' tags of stable test cases is obtained.
After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.
If analysis depth of the run results is zero, when the first suite is launched
a list of 'testrailid' tags of all test cases in the given status is obtained.
After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.
*Args:*\n
_suite_ - Robot Framework test suite object.
"""
tests = suite.tests
suite.tests = None
try:
if self.results_depth > 0:
suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_stable_tags_list))]
else:
suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_tags_list))]
except (RequestException, TimeoutError) as error:
self._log_to_parent_suite(suite, str(error))
示例4: run
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def run(self):
while not self.closed:
try:
segment, future = self.futures.get(block=True, timeout=0.5)
except queue.Empty:
continue
# End of stream
if future is None:
break
while not self.closed:
try:
result = future.result(timeout=0.5)
except futures.TimeoutError:
continue
except futures.CancelledError:
break
if result is not None:
self.write(segment, result)
break
self.close()
示例5: _check_executor
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def _check_executor(self, dt):
start = time()
try:
for future in as_completed(self._futures[:], 0):
self._futures.remove(future)
try:
result = future.result()
except Exception:
traceback.print_exc()
# make an error tile?
continue
if result is None:
continue
callback, args = result
callback(*args)
# capped executor in time, in order to prevent too much
# slowiness.
# seems to works quite great with big zoom-in/out
if time() - start > self.cap_time:
break
except TimeoutError:
pass
示例6: connect_and_auth
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def connect_and_auth(host, port, password, prot, loop, log, timeout=0.5):
"""Try to create a connection and authenticate to the
target FS ESL.
"""
msg = ("Failed to connect to server at '{}:{}'\n"
"Please check that FreeSWITCH is running and "
"accepting ESL connections.".format(host, port))
try:
await asyncio.wait_for(
loop.create_connection(lambda: prot, host, port),
timeout=timeout)
except (
ConnectionRefusedError, asyncio.TimeoutError, OSError,
futures.TimeoutError,
) as err:
raise ConnectionError(msg.format(host, port))
# TODO: consider using the asyncio_timeout lib here
try:
await asyncio.wait_for(prot.authenticate(), timeout)
except asyncio.TimeoutError:
raise ConnectionRefusedError(msg.format(host, port))
示例7: poll
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def poll(self, events, timeout=None,
return_when=asyncio.FIRST_COMPLETED):
"""Poll for any of a set of event types to be received for this session.
"""
awaitables = {}
for name in events:
awaitables[self.recv(name)] = name
done, pending = await asyncio.wait(
awaitables, timeout=timeout, return_when=return_when)
if done:
ev_dicts = []
for fut in done:
awaitables.pop(fut)
ev_dicts.append(fut.result())
return ev_dicts, awaitables.values()
else:
raise asyncio.TimeoutError(
"None of {} was received in {} seconds"
.format(events, timeout))
# call control / 'mod_commands' methods
# TODO: dynamically add @decorated functions to this class
# and wrap them using functools.update_wrapper ...?
示例8: _receive_credential
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def _receive_credential(self, result_type: CredentialType) -> Optional[str]:
if self.cancelled:
return None
self.current_status = {
"next_step": result_type.value,
}
if result_type == CredentialType.AUTHORIZATION:
self.current_status["manual_auth_url"] = make_login_url(self.device_name)
try:
return self.queue.send_to_async(self.current_status,
lambda: self._set_expecting(result_type))
except futures.TimeoutError:
self.cancel()
return None
except futures.CancelledError:
return None
示例9: test_zero_timeout
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def test_zero_timeout(self):
future1 = self.executor.submit(time.sleep, 2)
completed_futures = set()
try:
for future in futures.as_completed(
[CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE,
future1],
timeout=0):
completed_futures.add(future)
except futures.TimeoutError:
pass
self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
EXCEPTION_FUTURE,
SUCCESSFUL_FUTURE]),
completed_futures)
示例10: run
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def run(self):
self.brain.connect()
self.rtm_connect()
if not self.client.server.connected:
raise RuntimeError(
'Can not connect to slack client. Check your settings.'
)
while True:
events = self.read_message()
if events:
messages = self.extract_messages(events)
if messages:
with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
try:
executor.map(self.handle_message, messages)
except TimeoutError:
self.logger.error(traceback.format_exc())
else:
time.sleep(0.3)
示例11: queue_message
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def queue_message(self, channel_id:str, msg):
embed = '0'
if type(msg) == discord.Embed:
embed = '1'
msg = jsonpickle.encode(msg)
else:
msg = str(msg)
message_id = random.randint(0, 1000000)
payload = {'key': 'verysecretkey', 'id': message_id, 'channel_id': channel_id, 'message': msg, 'embed': embed}
try:
with aiohttp.Timeout(15):
async with self.session.post('http://ip:port/queue', data=payload) as r:
return True
except (asyncio.TimeoutError, aiohttp.errors.ClientConnectionError, aiohttp.errors.ClientError):
await asyncio.sleep(5)
return
except Exception as e:
print('queue error: '+str(e))
示例12: run_process
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def run_process(self, code, response=False):
try:
loop = self.bot.loop
exit_future = asyncio.Future(loop=loop)
create = loop.subprocess_exec(lambda: DataProtocol(exit_future),
*code, stdin=None, stderr=None)
transport, protocol = await asyncio.wait_for(create, timeout=30)
await exit_future
if response:
data = bytes(protocol.output)
return data.decode('ascii').rstrip()
return True
except asyncio.TimeoutError:
return False
except Exception as e:
print(e)
finally:
transport.close()
示例13: test_events_wrong_source
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def test_events_wrong_source(self):
objects = self.srv.get_objects_node()
o = objects.add_object(3, 'MyObject')
evgen = self.srv.get_event_generator(source=o)
myhandler = MySubHandler()
sub = self.opc.create_subscription(100, myhandler)
handle = sub.subscribe_events()
tid = datetime.utcnow()
msg = b"this is my msg "
evgen.trigger(tid, msg)
with self.assertRaises(TimeoutError): # we should not receive event
ev = myhandler.future.result(2)
# time.sleep(0.1)
sub.unsubscribe(handle)
sub.delete()
示例14: test_wait
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def test_wait(self):
mutable = []
@threads(N)
def side_effects():
mutable.append(True)
result = side_effects()
result._wait()
assert mutable[0]
@threads(N, timeout=0.1)
def side_effects_timeout():
time.sleep(1)
result = side_effects_timeout()
with self.assertRaises(TimeoutError):
result._wait()
示例15: submit
# 需要导入模块: from concurrent import futures [as 别名]
# 或者: from concurrent.futures import TimeoutError [as 别名]
def submit(self, label, command, opts):
"""Submit a bgutil command to run it asynchronously."""
task = BgUtilTask(label, datetime.now())
self.tasks.append(task)
def _done_callback(f):
try:
result = f.result()
task.completed(result)
except futures.CancelledError as e:
task.cancelled(e)
except futures.TimeoutError as e:
task.timed_out(e)
except Exception as e:
task.failed(e)
future = self._executor.submit(
self._wrap_command, task, context.accessor, command, opts
)
task.submitted()
future.add_done_callback(_done_callback)