Close the connection to the database.
(self)
| 342 | |
| 343 | @async_unsafe |
| 344 | def close(self): |
| 345 | """Close the connection to the database.""" |
| 346 | self.validate_thread_sharing() |
| 347 | self.run_on_commit = [] |
| 348 | |
| 349 | # Don't call validate_no_atomic_block() to avoid making it difficult |
| 350 | # to get rid of a connection in an invalid state. The next connect() |
| 351 | # will reset the transaction state anyway. |
| 352 | if self.closed_in_transaction or self.connection is None: |
| 353 | return |
| 354 | try: |
| 355 | self._close() |
| 356 | finally: |
| 357 | if self.in_atomic_block: |
| 358 | self.closed_in_transaction = True |
| 359 | self.needs_rollback = True |
| 360 | else: |
| 361 | self.connection = None |
| 362 | |
| 363 | # ##### Backend-specific savepoint management methods ##### |
| 364 |
no test coverage detected