aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2021-03-07 06:18:44 -0800
committerZac Medico <zmedico@gentoo.org>2021-03-07 06:37:46 -0800
commit9eea2af22c9e51475a4adba57fdded3a2a88c886 (patch)
treeeb7f23a8b57cf88647d8ea97bfceb6bd28e40ab9
parent_test_lock_fn: use _lock_manager and call unlock (diff)
downloadportage-9eea2af22c9e51475a4adba57fdded3a2a88c886.tar.gz
portage-9eea2af22c9e51475a4adba57fdded3a2a88c886.tar.bz2
portage-9eea2af22c9e51475a4adba57fdded3a2a88c886.zip
_writer: Use async and await syntax
Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/util/futures/_asyncio/streams.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/portage/util/futures/_asyncio/streams.py b/lib/portage/util/futures/_asyncio/streams.py
index ea5882dd3..7a8d4a3e0 100644
--- a/lib/portage/util/futures/_asyncio/streams.py
+++ b/lib/portage/util/futures/_asyncio/streams.py
@@ -1,4 +1,4 @@
-# Copyright 2018-2020 Gentoo Authors
+# Copyright 2018-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import errno
@@ -9,7 +9,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
'_emerge.PipeReader:PipeReader',
'portage.util.futures:asyncio',
)
-from portage.util.futures.compat_coroutine import coroutine
def _reader(input_file, loop=None):
@@ -55,8 +54,7 @@ class _Reader:
self._pipe_reader = None
-@coroutine
-def _writer(output_file, content, loop=None):
+async def _writer(output_file, content, loop=DeprecationWarning):
"""
Asynchronously write bytes to output file. The output file is
assumed to be in non-blocking mode. If an EnvironmentError
@@ -68,10 +66,9 @@ def _writer(output_file, content, loop=None):
@type output_file: file object
@param content: content to write
@type content: bytes
- @param loop: asyncio.AbstractEventLoop (or compatible)
- @type loop: event loop
+ @param loop: deprecated
"""
- loop = asyncio._wrap_loop(loop)
+ loop = asyncio.get_event_loop()
fd = output_file.fileno()
while content:
try:
@@ -82,7 +79,7 @@ def _writer(output_file, content, loop=None):
waiter = loop.create_future()
loop.add_writer(fd, lambda: waiter.done() or waiter.set_result(None))
try:
- yield waiter
+ await waiter
finally:
# The loop and output file may have been closed.
if not loop.is_closed():