- Decode connection errors in the ``client_encoding`` specified in the
connection string, if available (:ticket:`#194`).
+- Fix possible warnings in objects deletion on interpreter shutdown
+ (:ticket:`#198`).
Psycopg 3.0.7
# Copyright (C) 2020-2021 The Psycopg Team
import logging
-import warnings
import threading
from types import TracebackType
from typing import Any, Callable, cast, Dict, Generator, Generic, Iterator
from typing import List, NamedTuple, Optional, Type, TypeVar, Tuple, Union
from typing import overload, TYPE_CHECKING
from weakref import ref, ReferenceType
+from warnings import warn
from functools import partial
from contextlib import contextmanager
if hasattr(self, "_pool"):
return
- warnings.warn(
+ warn(
f"connection {self} was deleted while still open."
f" Please use 'with' or '.close()' to close the connection",
ResourceWarning,
# Copyright (C) 2020-2021 The Psycopg Team
-import os
-import logging
import sys
+import logging
+from os import getpid
from weakref import ref
from functools import partial
from .misc import error_message, connection_summary
from ._enums import Format, ExecStatus, Trace
+# Imported locally to call them from __del__ methods
+from ._pq_ctypes import PQclear, PQfinish, PQfreeCancel, PQstatus
+
if TYPE_CHECKING:
from . import abc
)
impl.PQsetNoticeReceiver(pgconn_ptr, self._notice_receiver, None)
- self._procpid = os.getpid()
+ self._procpid = getpid()
def __del__(self) -> None:
# Close the connection only if it was created in this process,
# not if this object is being GC'd after fork.
- if os.getpid() == self._procpid:
+ if getpid() == self._procpid:
self.finish()
def __repr__(self) -> str:
def finish(self) -> None:
self._pgconn_ptr, p = None, self._pgconn_ptr
if p:
- impl.PQfinish(p)
+ PQfinish(p)
@property
def pgconn_ptr(self) -> Optional[int]:
@property
def status(self) -> int:
- return impl.PQstatus(self._pgconn_ptr)
+ return PQstatus(self._pgconn_ptr)
@property
def transaction_status(self) -> int:
def clear(self) -> None:
self._pgresult_ptr, p = None, self._pgresult_ptr
if p:
- impl.PQclear(p)
+ PQclear(p)
@property
def pgresult_ptr(self) -> Optional[int]:
"""
self.pgcancel_ptr, p = None, self.pgcancel_ptr
if p:
- impl.PQfreeCancel(p)
+ PQfreeCancel(p)
def cancel(self) -> None:
"""Requests that the server abandon processing of the current command.
# Copyright (C) 2020-2021 The Psycopg Team
-import warnings
from typing import Any, AsyncIterator, Generic, List, Iterable, Iterator
from typing import Optional, TypeVar, TYPE_CHECKING
+from warnings import warn
from . import pq
from . import sql
def __del__(self) -> None:
if not self.closed:
- warnings.warn(
+ warn(
f"the server-side cursor {self} was deleted while still open."
f" Please use 'with' or '.close()' to close the cursor properly",
ResourceWarning,
def __del__(self) -> None:
if not self.closed:
- warnings.warn(
+ warn(
f"the server-side cursor {self} was deleted while still open."
f" Please use 'with' or '.close()' to close the cursor properly",
ResourceWarning,