本文整理汇总了Python中contextlib.AbstractContextManager方法的典型用法代码示例。如果您正苦于以下问题:Python contextlib.AbstractContextManager方法的具体用法?Python contextlib.AbstractContextManager怎么用?Python contextlib.AbstractContextManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contextlib
的用法示例。
在下文中一共展示了contextlib.AbstractContextManager方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import AbstractContextManager [as 别名]
def connect(self) -> contextlib.AbstractContextManager:
"""Context manager to connect to a given database and clean up on exit.
This allows you to pool interactions with the database to prevent possibly
expensive reconnects, or to roll back several interactions if one of them fails.
Note:
Make sure to call :meth:`create` on a fresh database before using this method.
Example:
>>> import terracotta as tc
>>> driver = tc.get_driver('tc.sqlite')
>>> with driver.connect():
... for keys, dataset in datasets.items():
... # connection will be kept open between insert operations
... driver.insert(keys, dataset)
"""
pass
示例2: connect
# 需要导入模块: import contextlib [as 别名]
# 或者: from contextlib import AbstractContextManager [as 别名]
def connect(self) -> AbstractContextManager:
return self._connect(check=True)