本文整理匯總了Python中warnings.warning方法的典型用法代碼示例。如果您正苦於以下問題:Python warnings.warning方法的具體用法?Python warnings.warning怎麽用?Python warnings.warning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類warnings
的用法示例。
在下文中一共展示了warnings.warning方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _limit_inlines
# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warning [as 別名]
def _limit_inlines(max_inlines, images_iter):
if max_inlines is not None:
images_list = list(images_iter)
if max_inlines > len(images_list):
warn_msg = (
f"The number of max inlines {max_inlines} is greater"
f"than the number of inlines found {len(images_list)}."
f"Setting max inlines to {len(images_list)}"
)
warnings.warning(warn_msg)
max_inlines = len(images_list)
images_iter = images_list
else:
shuffled_list = random.shuffle(images_list)
images_iter = take(max_inlines, shuffled_list)
return images_iter, max_inlines
示例2: transfer
# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warning [as 別名]
def transfer(self):
"""
Mark an object for ownership transfer. This object, when pickled, will
unpickle into an owning model that frees resources when closed. Used to
transfer ownership of shared memory resources from child processes to
parent processes. Such an object should only be unpickled once.
The default implementation sets the ``is_owner`` attribute to ``'transfer'``.
Returns:
``self`` (for convenience)
"""
if not self.is_owner:
warnings.warning('non-owning objects should not be transferred', stacklevel=1)
else:
self.is_owner = 'transfer'
return self
示例3: __init__
# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warning [as 別名]
def __init__(
self, optimizer, t_max: int, eta_min: float = 0., last_epoch: int = -1, factor: float = 1.
) -> None:
assert t_max > 0
assert eta_min >= 0
if t_max == 1 and factor == 1:
warnings.warning(
"Cosine annealing scheduler will have no effect on the learning "
"rate since T_max = 1 and factor = 1."
)
self.t_max = t_max
self.eta_min = eta_min
self.factor = factor
self._last_restart: int = 0
self._cycle_counter: int = 0
self._cycle_factor: float = 1.
self._updated_cycle_len: int = t_max
self._initialized: bool = False
super(CosineWithRestarts, self).__init__(optimizer, last_epoch)
示例4: stop
# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warning [as 別名]
def stop(self, timeout=5):
"""Terminate all worker threads.
Args:
timeout (int): time to wait for threads to stop gracefully
"""
# for compatability, negative timeouts are treated like None
# TODO: treat negative timeouts like already expired timeouts
if timeout is not None and timeout < 0:
timeout = None
warnings.warning(
'In the future, negative timeouts to Server.stop() '
'will be equivalent to a timeout of zero.',
stacklevel=2,
)
if timeout is not None:
endtime = time.time() + timeout
# Must shut down threads here so the code that calls
# this method can know when all threads are stopped.
for worker in self._threads:
self._queue.put(_SHUTDOWNREQUEST)
ignored_errors = (
# TODO: explain this exception.
AssertionError,
# Ignore repeated Ctrl-C. See cherrypy#691.
KeyboardInterrupt,
)
for worker in self._clear_threads():
remaining_time = timeout and endtime - time.time()
try:
worker.join(remaining_time)
if worker.is_alive():
# Timeout exhausted; forcibly shut down the socket.
self._force_close(worker.conn)
worker.join()
except ignored_errors:
pass
示例5: memory
# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import warning [as 別名]
def memory(self):
"""Return function's memory attribute"""
try:
return self.function.memory
except:
warnings.warning(f'Function of {self.name} (self.function.name) has no memory attribute')