本文整理匯總了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)