Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZEO.asyncio: switch to async/await style #218

Merged
merged 34 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3ca4d5d
Drop Python2 support
d-maurer May 18, 2022
7f574ec
ZEO.asyncio: switch to async/await style
d-maurer Apr 2, 2022
d8673b5
Revert "asyncio: Fix occasional `ValueError: loop argument must agree…
navytux Jan 8, 2023
d0f0709
Drop use of six
navytux May 23, 2022
3ea9bf3
Drop use of mock egg
d-maurer May 23, 2022
3458abc
drop Python 3.5 support
d-maurer May 21, 2022
1494802
Drop use of manuel
navytux May 23, 2022
1787d34
No longer pin msgpack < 1
navytux May 23, 2022
41288d0
*: Replace super(Type, self) -> super()
d-maurer Apr 2, 2022
6d9d2c4
ZEO.asyncio: No need to import asyncio through compat
d-maurer Apr 2, 2022
2c9c7eb
*: No need to import threading-related bits through compat
d-maurer Apr 2, 2022
1111c3e
asyncio.smp: Further optimize `SizedMessageProtocol` regarding readab…
d-maurer Jun 1, 2022
fceb295
*: No need to use `class X(object)`
d-maurer Apr 2, 2022
9cff397
asyncio.tests: Python3 handles *argv and keyword arguments with defau…
d-maurer Jan 8, 2023
e17cd2a
ZEO6 α1
d-maurer Apr 2, 2022
a5573aa
Merge branch 'knext' into knext+kpy3
navytux Jan 13, 2023
fd030ef
Merge branch 'knext' into knext+kpy3
navytux Jan 14, 2023
7ecc6a3
Drop support for Python3.6
navytux Jan 14, 2023
a088784
Merge branch 'master' into knext+kpy3
navytux Jan 18, 2023
584dc8f
Merge branch master into knext+kpy3
navytux Jan 18, 2023
927fcdd
- fix DeprecationWarnings and no longer ignore ResourceWarnings
dataflake Jan 19, 2023
e07be0a
- fix up .meta.toml [ci skip]
dataflake Jan 19, 2023
933764f
- remove obsolete compatibility entries
dataflake Jan 19, 2023
32091b5
fixup! ZEO.asyncio: switch to async/await style
navytux Jan 19, 2023
1f16336
*: Import BytesIO and StringIO directly from io
navytux Jan 19, 2023
9c897b0
Merge branch 'knext+kpy3' of github.com:zopefoundation/ZEO into knext…
dataflake Jan 19, 2023
bac6d86
- More Python 2 cleanup with `pyupgrade`
dataflake Jan 19, 2023
2a9d3b3
Merge branch 'knext+kpy3' of github.com:zopefoundation/ZEO into knext…
dataflake Jan 19, 2023
b4507e5
Remove ZEO/hash.py
navytux Jan 19, 2023
02ceb12
- small fixes from eyeballing the PR diff [ci skip]
dataflake Jan 19, 2023
6342939
asyncio.client: Switch ._connecting to be native asyncio Task instead…
navytux Jan 19, 2023
e3b8658
add comment about the special task use for the `connect` coroutine
d-maurer Jan 20, 2023
d08ac83
make test `client-config.test` more robust against application/ZEO race
d-maurer Jan 23, 2023
3ca79a6
better highlight the limitations of ZEO `Future`s and `Task`s
d-maurer Jan 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ jobs:
config:
# [Python version, tox env]
- ["3.9", "lint"]
- ["2.7", "py27"]
- ["3.5", "py35"]
- ["3.6", "py36"]
- ["3.7", "py37"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["pypy-2.7", "pypy"]
- ["pypy-3.7", "pypy3"]
- ["3.9", "docs"]
- ["3.9", "coverage"]
- ["2.7", "py27-msgpack1"]
- ["3.7", "py37-msgpack1"]
- ["3.7", "py37-uvloop"]
- ["3.7", "py37-zodbmaster"]
Expand Down Expand Up @@ -74,7 +69,7 @@ jobs:
- name: Coverage
if: matrix.config[1] == 'coverage'
run: |
pip install coveralls coverage-python-version
pip install coveralls
coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 12 additions & 4 deletions .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "200573eb414d2228d463da3de7d71a6d6335a704"
commit-id = "78e0868c"

[python]
with-windows = false
with-pypy = true
with-future-python = false
with-legacy-python = true
with-docs = true
with-sphinx-doctests = false
with-macos = false
Expand All @@ -27,10 +26,19 @@ testenv-deps = [
"uvloop: uvloop",
]
testenv-setenv = [
"!py27-!pypy: PYTHONWARNINGS=ignore::ResourceWarning",
"msgpack1: ZEO_MSGPACK=1",
]

[flake8]
additional-config = [
"# E501 line too long",
"# F401 unused import",
"per-file-ignores =",
" src/ZEO/tests/test_cache.py: E501",
" src/ZEO/_compat.py: F401",
" src/ZEO/asyncio/compat.py: F401",
]

[coverage]
fail-under = 53

Expand All @@ -41,6 +49,7 @@ additional-rules = [
"include log.ini",
"recursive-include src *.csr",
"recursive-include src *.pem",
"recursive-include src *.pyx",
"recursive-include src *.rst",
"recursive-include src *.test",
"recursive-include src *.txt",
Expand All @@ -49,7 +58,6 @@ additional-rules = [

[github-actions]
additional-config = [
"- [\"2.7\", \"py27-msgpack1\"]",
"- [\"3.7\", \"py37-msgpack1\"]",
"- [\"3.7\", \"py37-uvloop\"]",
"- [\"3.7\", \"py37-zodbmaster\"]",
Expand Down
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ Changelog
6.0.0 (unreleased)
------------------

- Drop support for Python 2.7, 3.5, 3.6.

5.4.0 (2023-01-18)
- Switch to using `async/await` directly instead of `@coroutine/yield`


5.4.0 (unreleased)
------------------

- Reimplement and streamline the ``asyncio`` part of the ``ClientStorage``
implementation:

- switch from futures with explicit callbacks to `async/await`-like style
- use standard ``asyncio`` features to implement timeouts
- redesign the API of the class implementing the ZEO client protocol
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ recursive-include docs *.txt
recursive-include docs Makefile

recursive-include src *.py
recursive-include src *.pyx
include *.py
include COPYING
include log.ini
recursive-include src *.csr
recursive-include src *.pem
recursive-include src *.pyx
recursive-include src *.rst
recursive-include src *.test
recursive-include src *.txt
Expand Down
14 changes: 10 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[bdist_wheel]
universal = 1
universal = 0

[flake8]
doctests = 1
# E501 line too long
# F401 unused import
per-file-ignores =
src/ZEO/tests/test_cache.py: E501
src/ZEO/_compat.py: F401
src/ZEO/asyncio/compat.py: F401

[check-manifest]
ignore =
Expand All @@ -16,9 +22,9 @@ ignore =
force_single_line = True
combine_as_imports = True
sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
known_third_party = six, docutils, pkg_resources
known_zope =
known_first_party =
known_third_party = six, docutils, pkg_resources
known_zope =
known_first_party =
default_section = ZOPE
line_length = 79
lines_after_imports = 2
15 changes: 2 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

install_requires = [
'ZODB >= 5.1.1',
'six',
'transaction >= 2.0.3',
'persistent >= 4.1.0',
'zc.lockfile',
Expand All @@ -34,10 +33,8 @@
'ZODB >= 5.5.1',
'ZopeUndo',
'zope.testing',
'manuel',
'transaction',
'mock',
'msgpack < 1',
'msgpack',
'zdaemon',
'zope.testrunner',
]
Expand All @@ -64,11 +61,7 @@
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand All @@ -91,10 +84,6 @@
'msgpack': [
'msgpack-python'
],
':python_version == "2.7"': [
'futures',
'trollius',
],
'docs': [
'Sphinx',
'repoze.sphinx.autointerface',
Expand All @@ -111,5 +100,5 @@
zeo-nagios = ZEO.nagios:main
""",
include_package_data=True,
python_requires='>=2.7.9,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',
python_requires='>=3.7',
)
29 changes: 14 additions & 15 deletions src/ZEO/ClientStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import stat
import sys
import threading
from threading import get_ident
import time
import weakref
from binascii import hexlify
Expand All @@ -37,10 +38,8 @@
import ZODB.ConflictResolution
import ZODB.interfaces
import zope.interface
import six

from persistent.TimeStamp import TimeStamp
from ZEO._compat import get_ident
from ZEO._compat import WIN
from ZEO.Exceptions import ClientDisconnected
from ZEO.TransactionBuffer import TransactionBuffer
Expand Down Expand Up @@ -262,12 +261,12 @@ def __init__(self, addr, storage='1', cache_size=20 * MB,

self.__name__ = name or str(addr) # Standard convention for storages

if isinstance(addr, six.string_types):
if isinstance(addr, str):
if WIN:
raise ValueError("Unix sockets are not available on Windows")
addr = [addr]
elif (isinstance(addr, tuple) and len(addr) == 2 and
isinstance(addr[0], six.string_types) and
isinstance(addr[0], str) and
isinstance(addr[1], int)):
addr = [addr]

Expand Down Expand Up @@ -401,7 +400,7 @@ def _check_blob_size(self, bytes=None):
args=(self.blob_dir, target),
name="%s zeo client check blob size thread" % self.__name__,
)
check_blob_size_thread.setDaemon(True)
check_blob_size_thread.daemon = True
check_blob_size_thread.start()
self._check_blob_size_thread = check_blob_size_thread

Expand All @@ -412,7 +411,7 @@ def registerDB(self, db):

The storage isn't really ready to use until after this call.
"""
super(ClientStorage, self).registerDB(db)
super().registerDB(db)
self._db = db

def is_connected(self, test=False):
Expand Down Expand Up @@ -493,7 +492,7 @@ def set_server_addr(self, addr):
host = addr[0]
try:
canonical, aliases, addrs = socket.gethostbyaddr(host)
except socket.error as err:
except OSError as err:
logger.debug("%s Error resolving host: %s (%s)",
self.__name__, host, err)
canonical = host
Expand All @@ -507,7 +506,7 @@ def sortKey(self):
if self._server_addr is None:
raise ClientDisconnected
else:
return '%s:%s' % (self._storage, self._server_addr)
return f'{self._storage}:{self._server_addr}'

def notify_disconnected(self):
"""Internal: notify that the server connection was terminated.
Expand Down Expand Up @@ -537,7 +536,7 @@ def getName(self):
connected.

"""
return "%s (%s)" % (
return "{} ({})".format(
self.__name__,
self.is_connected() and "connected" or "disconnected")

Expand Down Expand Up @@ -805,7 +804,7 @@ def openCommittedBlobFile(self, oid, serial, blob=None):
return open(blob_filename, 'rb')
else:
return ZODB.blob.BlobFile(blob_filename, 'r', blob)
except (IOError):
except (OSError):
# The file got removed while we were opening.
# Fall through and try again with the protection of the lock.
pass
Expand Down Expand Up @@ -1131,7 +1130,7 @@ def server_status(self, timeout=None):
return self._call('server_status', timeout=timeout)


class TransactionIterator(object):
class TransactionIterator:

def __init__(self, storage, iid, *args):
self._storage = storage
Expand Down Expand Up @@ -1183,7 +1182,7 @@ def __iter__(self):
return self._storage._setup_iterator(RecordIterator, riid)


class RecordIterator(object):
class RecordIterator:

def __init__(self, storage, riid):
self._riid = riid
Expand All @@ -1209,7 +1208,7 @@ def __next__(self):
next = __next__


class BlobCacheLayout(object):
class BlobCacheLayout:

size = 997

Expand All @@ -1220,7 +1219,7 @@ def getBlobFilePath(self, oid, tid):
base, rem = divmod(utils.u64(oid), self.size)
return os.path.join(
str(rem),
"%s.%s%s" % (base, hexlify(tid).decode('ascii'),
"{}.{}{}".format(base, hexlify(tid).decode('ascii'),
ZODB.blob.BLOB_SUFFIX)
)

Expand Down Expand Up @@ -1382,7 +1381,7 @@ def open_cache(cache, var, client, storage, cache_size):
if cache is None:
if client:
cache = os.path.join(var or os.getcwd(),
"%s-%s.zec" % (client, storage))
f'{client}-{storage}.zec')
else:
# ephemeral cache
return ClientCache(None, cache_size)
Expand Down
Loading