-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
-------- kirr: ZEO6 is going to support Python3 - see discussion around #195 (comment) . This patch was extracted from #195 .
-------- kirr: Switch to using async def f(): await g() instead of @coroutine def f(): yield g() Remove corresponding runtime support from CoroutineExecutor. Extracted from #195
… with Future`" This reverts commit f85b45b. We stopped support for py2 and trollius. No need to keep on using trollius-related workarounds.
As we dropped Python2 support, using six is no longer necessary, and we can use Python3 features directly. Suggested by @d-maurer.
-------- kirr: With Python3 we can use builtin unittest.mock instead. This patch was extracted from #195
-------- As @d-maurer says unittest.mock in Python3.5 lacks some functionality that we use, e.g. assert_called_once. Python 3.5 was marked as EOL in 2017, and it stopped receiving security updates in 2020. It should be safe to drop support for it.
Msgpack egg was pinned to be < 1 in 503dccb (prevent deprecation warning and move to latest msgpack supporting Python 2). We no longer support Python2, thus we no longer need to pin msgpack to the version that still supports it.
-------- kirr: Python3 allows to use just super() without arguments. Extracted from #195
-------- kirr: We dropped support for py2 and trollius, and now plain `import asyncio` always works. Extracted from #195
-------- kirr: Extracted from #195
…ility and efficiency use `nonlocal` (instead of mutable wrapping) for shared variables -------- kirr: no need to change _smp.pyx since for cdef classes self.var works efficiently without dict lookup. Extracted from #195
-------- kirr: On python3 there are no old-style and new-style classes. All classes are new style and object is always used as default base class. Extracted from #195
…lts just ok -------- kirr: Extracted from #195
It is a question whether we want to merge this - from #195 (comment):
|
Kirill Smelkov wrote at 2023-1-8 10:50 -0800:
...
In #200 (comment) you
said that _"dropping Python 2 support gives no gain by itself. Only if
gainfull things (I think of #195) require dropping Python 2 support, I would
merge #200."_ So from this point of view, if maybe we are ok to keep our
`async`/`await`-style coroutines being implemented with similar
***@***.***`/`yield` syntax, there is no real need to merge this and to drop
py2 support.
I got the feeling that all `zopefoundation` packages will
drop Python 2 support the next time, they are reconfigured with
the `meta` tools.
Thus, after you have merged the Py2/Py3 changes, you should
likely make a 5.x branch.
|
Thanks, I see. |
We are in the slow process of dropping support for all Python versions up to and including Python 3.6. Many dependencies have already done that and the pain of supporting those old Python versions is now higher than any gain. |
I see, Jens. Thanks for clarifying. So from this point of view it indeed makes sense to want to merge this PR. |
IMHO you should also remove Python 3.6 support before merging. |
* knext: asyncio: Remove support for calling ConcurrentTask.cancel from non-IO threads asyncio: Don't reset current loop after loop_run_* completes fix discrepancy between `futures.py` and `_futures.pyx` (reported by @navitux) implement `ConcurrentTask.cancel` based on the event loop rather than the thread id asyncio.futures: Simplify ConcurrentTask.cancel() tests: Remove explicit `def test_suite` where test suite definition is trivial tests: Remove explicit calls to unittest.main Remove support for 'python setup.py test' fixup! asyncio.futures: Implement cancellation thoroughly fixup! asyncio.client: make `prefetch` more reliable fixup! asyncio.futures: Add own coroutine executor fixup! asyncio.futures: Implement cancellation thoroughly
@dataflake, would you please clarify about why? Currently supporting py3.6 does not add big extra cost. |
It is EOF and we're removing support on all packages we touch in the zopefoundatiom organization. |
* knext: fixup! asyncio.futures: Mimic async/await with plain yield and @coroutine decorator
@dataflake says at #218 (comment) : IMHO you should also remove Python 3.6 support before merging. ... It is EOF and we're removing support on all packages we touch in the zopefoundatiom organization.
Thanks, Jens. I removed it in b4507e55. |
Btw, Dieter, any idea about https://github.com/zopefoundation/ZEO/actions/runs/3958283359/jobs/6779667424 ? |
Our tasks not only execute callbacks immediately, they ignore also the task context (used e.g. for context variables). We know that our coroutines make no use of the task context; however, a priori, we know nothing about the "create connection coroutine". In my opinion, it would therefore be safer to use |
… of our Task Even though everything seems to be working with our Task implementation @d-maurer suggests to use native Task implementation for coroutine code implemented outside of ZEO because this way it is potentially safer: #218 (comment) -> Let it be this way.
Dieter, thanks for feedback. Ok, let it be this way. I've changed Kirill |
This is a race condition caused by a buggy test: The log record examination exists primarily to help in the analysis of earlier problems with the closing logic: in some cases, the >>> def check_log_records(records):
... records = [r.message for r in records]
... return any("bug" in r for r in records) and records else [] |
Dieter, thanks for the approval and for explaining what is going on with
I agree. Would you please do this, probably with also putting a comment regarding the race you describe? I mean this is your test and your code, and it was you to analyze what is going on here. It looks logical for you to make the fixing commit. @dataflake, are you also ok with merging this PR after we do the above? |
Kirill Smelkov wrote at 2023-1-20 00:52 -0800:
...
I agree. Would you please do this ...
Ok -- when I have finished my current project.
|
Thanks. |
Dieter, thanks for the fixups. Do I understand it right that this PR should be ok to be merged now? |
Jens, we seem to be done. Do you agree with merging this? |
Yes you can go ahead and merge |
Dieter, Jens, thanks for feedback and approvals. I've merged this via 59de2de3. Using the occassion I have a question regarding 5.x branch: now since hereby PR is merged, I want to pick some fixes and improvements from master to 5.x . For example I would like to pick e.g. d08ac83, removal of |
I think it's fine if you do this by yourself. |
This file was used for py2.6 compatibility which is long gone and nothing imports ZEO.hash this days anymore. Confirmed by @dataflake: #218 (comment) (cherry-picked from b4507e5)
Thanks, Jens. I picked up the following patches to 5.x for now: I did not picked change of Hope my backports are ok. |
You do not need to verify every detail with me. I don't have much interest in the ZEO |
I see. Thanks for feedback. |
Second part of Dieter's work from #195 :
async/await
directly instead of@coroutine/yield