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

For bug 716636, revert changes related to bug 709746 #541

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
17df30b
Revert "Rename PORTAGE_LOG_FILTER_FILE_CMD from PORTAGE_LOG_FILTER_FILE"
zmedico Apr 8, 2020
66c6619
Revert "SpawnProcess: cancel _main_task in _unregister (bug 711174)"
zmedico Apr 8, 2020
c2ffa94
Revert "_BinpkgFetcherProcess: fix async_lock event loop recursion (b…
zmedico Apr 8, 2020
a0148f9
Revert "Support PORTAGE_LOG_FILTER_FILE (bug 709746)"
zmedico Apr 8, 2020
79a46f6
Revert "EbuildBuildDir: cancel current tasks for CancelledError"
zmedico Apr 8, 2020
4122a1e
Revert "AsyncScheduler: cancel task after _task_coroutine CancelledEr…
zmedico Apr 8, 2020
044012f
Revert "CompositeTask: call self.cancel() for _start_task CancelledEr…
zmedico Apr 8, 2020
f7e36d1
Revert "SpawnProcess: cancel pipe_logger after async_start CancelledE…
zmedico Apr 8, 2020
7e29188
Revert "SpawnProcess: make _main cancel pipe_logger when appropriate"
zmedico Apr 8, 2020
971124a
Revert "SpawnProcess: only cancel self._main_task if it's not done"
zmedico Apr 8, 2020
d244390
Revert "SpawnProcess: add _main coroutine"
zmedico Apr 8, 2020
f1e9389
Revert "PipeLogger: non-blocking write to pipe (bug 709746)"
zmedico Apr 8, 2020
28adac2
Revert "SpawnProcess: use async_start method (bug 709746)"
zmedico Apr 8, 2020
174b624
Revert "ForkExecutor: use async_start method"
zmedico Apr 8, 2020
5f0f1da
Revert "EbuildBuildDir: use async_start method"
zmedico Apr 8, 2020
bf15057
Revert "AsyncScheduler: use async_start method"
zmedico Apr 8, 2020
acd8f3a
Revert "AsynchronousTask: Call _start_hook after _start_async"
zmedico Apr 8, 2020
a070010
Revert "EbuildPhase: add _async_start coroutine"
zmedico Apr 8, 2020
62ee9ec
Revert "AbstractEbuildProcess: add _async_start coroutine"
zmedico Apr 8, 2020
71ae5a5
Revert "AsynchronousTask: add coroutine async_start method"
zmedico Apr 8, 2020
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
37 changes: 25 additions & 12 deletions lib/_emerge/AbstractEbuildProcess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2020 Gentoo Authors
# Copyright 1999-2019 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import errno
Expand All @@ -19,7 +19,6 @@
from portage.package.ebuild._ipc.QueryCommand import QueryCommand
from portage import shutil, os
from portage.util.futures import asyncio
from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util._pty import _create_pty_or_pipe
from portage.util import apply_secpass_permissions

Expand All @@ -31,7 +30,7 @@ class AbstractEbuildProcess(SpawnProcess):

__slots__ = ('phase', 'settings',) + \
('_build_dir', '_build_dir_unlock', '_ipc_daemon',
'_exit_command', '_exit_timeout_id')
'_exit_command', '_exit_timeout_id', '_start_future')

_phases_without_builddir = ('clean', 'cleanrm', 'depend', 'help',)
_phases_interactive_whitelist = ('config',)
Expand All @@ -56,10 +55,6 @@ def __init__(self, **kwargs):
self.phase = phase

def _start(self):
self.scheduler.run_until_complete(self._async_start())

@coroutine
def _async_start(self):

need_builddir = self.phase not in self._phases_without_builddir

Expand All @@ -74,7 +69,7 @@ def _async_start(self):
self._eerror(textwrap.wrap(msg, 72))
self.returncode = 1
self._async_wait()
coroutine_return()
return

# Check if the cgroup hierarchy is in place. If it's not, mount it.
if (os.geteuid() == 0 and platform.system() == 'Linux'
Expand Down Expand Up @@ -147,7 +142,11 @@ def _async_start(self):
if 'PORTAGE_BUILDDIR_LOCKED' not in self.settings:
self._build_dir = EbuildBuildDir(
scheduler=self.scheduler, settings=self.settings)
yield self._build_dir.async_lock()
self._start_future = self._build_dir.async_lock()
self._start_future.add_done_callback(
functools.partial(self._start_post_builddir_lock,
start_ipc_daemon=start_ipc_daemon))
return
else:
self.settings.pop('PORTAGE_IPC_DAEMON', None)
else:
Expand All @@ -168,6 +167,22 @@ def _async_start(self):
else:
self.settings.pop('PORTAGE_EBUILD_EXIT_FILE', None)

self._start_post_builddir_lock(start_ipc_daemon=start_ipc_daemon)

def _start_post_builddir_lock(self, lock_future=None, start_ipc_daemon=False):
if lock_future is not None:
if lock_future is not self._start_future:
raise AssertionError('lock_future is not self._start_future')
self._start_future = None
if lock_future.cancelled():
self._build_dir = None
self.cancelled = True
self._was_cancelled()
self._async_wait()
return

lock_future.result()

if start_ipc_daemon:
self.settings['PORTAGE_IPC_DAEMON'] = "1"
self._start_ipc_daemon()
Expand All @@ -181,10 +196,8 @@ def _async_start(self):
null_fd = os.open('/dev/null', os.O_RDONLY)
self.fd_pipes[0] = null_fd

self.log_filter_file = self.settings.get('PORTAGE_LOG_FILTER_FILE_CMD')

try:
yield SpawnProcess._async_start(self)
SpawnProcess._start(self)
finally:
if null_fd is not None:
os.close(null_fd)
Expand Down
15 changes: 3 additions & 12 deletions lib/_emerge/AsynchronousLock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2020 Gentoo Authors
# Copyright 2010-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import fcntl
Expand All @@ -21,7 +21,6 @@
from portage.localization import _
from portage.locks import lockfile, unlockfile
from portage.util import writemsg_level
from portage.util.futures.compat_coroutine import coroutine
from _emerge.AbstractPollTask import AbstractPollTask
from _emerge.AsynchronousTask import AsynchronousTask
from _emerge.SpawnProcess import SpawnProcess
Expand All @@ -44,10 +43,6 @@ class AsynchronousLock(AsynchronousTask):
_use_process_by_default = True

def _start(self):
self.scheduler.run_until_complete(self._async_start())

@coroutine
def _async_start(self):

if not self._force_async:
try:
Expand All @@ -70,7 +65,7 @@ def _async_start(self):
_force_dummy=self._force_dummy)

self._imp.addExitListener(self._imp_exit)
yield self._imp.async_start()
self._imp.start()

def _imp_exit(self, imp):
# call exit listeners
Expand Down Expand Up @@ -188,10 +183,6 @@ class _LockProcess(AbstractPollTask):
('_acquired', '_kill_test', '_proc', '_files', '_unlock_future')

def _start(self):
self.scheduler.run_until_complete(self._async_start())

@coroutine
def _async_start(self):
in_pr, in_pw = os.pipe()
out_pr, out_pw = os.pipe()
self._files = {}
Expand Down Expand Up @@ -220,7 +211,7 @@ def _async_start(self):
fd_pipes={0:out_pr, 1:in_pw, 2:sys.__stderr__.fileno()},
scheduler=self.scheduler)
self._proc.addExitListener(self._proc_exit)
yield self._proc.async_start()
self._proc.start()
os.close(out_pr)
os.close(in_pw)

Expand Down
35 changes: 6 additions & 29 deletions lib/_emerge/AsynchronousTask.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright 1999-2020 Gentoo Authors
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import signal

from portage import os
from portage.util.futures import asyncio
from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.SlotObject import SlotObject

class AsynchronousTask(SlotObject):
Expand All @@ -23,38 +22,12 @@ class AsynchronousTask(SlotObject):

_cancelled_returncode = - signal.SIGINT

@coroutine
def async_start(self):
try:
if self._was_cancelled():
raise asyncio.CancelledError
yield self._async_start()
if self._was_cancelled():
raise asyncio.CancelledError
except asyncio.CancelledError:
self.cancel()
self._was_cancelled()
self._async_wait()
raise
finally:
self._start_hook()

@coroutine
def _async_start(self):
self._start()
coroutine_return()
yield None

def start(self):
"""
Start an asynchronous task and then return as soon as possible.
"""
self._start()
self._start_hook()

def _start(self):
self.returncode = os.EX_OK
self._async_wait()
self._start()

def async_wait(self):
"""
Expand All @@ -76,6 +49,10 @@ def async_wait(self):
self._async_wait()
return waiter

def _start(self):
self.returncode = os.EX_OK
self._async_wait()

def isAlive(self):
return self.returncode is None

Expand Down
9 changes: 2 additions & 7 deletions lib/_emerge/BinpkgExtractorAsync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2020 Gentoo Authors
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import logging
Expand All @@ -10,7 +10,6 @@
compression_probe,
_compressors,
)
from portage.util.futures.compat_coroutine import coroutine
from portage.process import find_binary
from portage.util import (
shlex_split,
Expand All @@ -28,10 +27,6 @@ class BinpkgExtractorAsync(SpawnProcess):
_shell_binary = portage.const.BASH_BINARY

def _start(self):
self.scheduler.run_until_complete(self._async_start())

@coroutine
def _async_start(self):
tar_options = ""
if "xattr" in self.features:
process = subprocess.Popen(["tar", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down Expand Up @@ -110,4 +105,4 @@ def _async_start(self):
portage._shell_quote(self.image_dir),
128 + signal.SIGPIPE)]

yield SpawnProcess._async_start(self)
SpawnProcess._start(self)
41 changes: 17 additions & 24 deletions lib/_emerge/BinpkgFetcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2020 Gentoo Authors
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

import functools
Expand All @@ -16,8 +16,6 @@
from portage import os
from portage.util._async.AsyncTaskFuture import AsyncTaskFuture
from portage.util._pty import _create_pty_or_pipe
from portage.util.futures import asyncio
from portage.util.futures.compat_coroutine import coroutine

if sys.hexversion >= 0x3000000:
long = int
Expand Down Expand Up @@ -87,10 +85,6 @@ class _BinpkgFetcherProcess(SpawnProcess):
__slots__ = ("pkg", "pretend", "locked", "pkg_path", "_lock_obj")

def _start(self):
self.scheduler.run_until_complete(self._async_start())

@coroutine
def _async_start(self):
pkg = self.pkg
pretend = self.pretend
bintree = pkg.root_config.trees["bintree"]
Expand Down Expand Up @@ -164,7 +158,7 @@ def _async_start(self):
self.env = fetch_env
if settings.selinux_enabled():
self._selinux_type = settings["PORTAGE_FETCH_T"]
yield SpawnProcess._async_start(self)
SpawnProcess._start(self)

def _pipe(self, fd_pipes):
"""When appropriate, use a pty so that fetcher progress bars,
Expand Down Expand Up @@ -206,7 +200,6 @@ def sync_timestamp(self):
except OSError:
pass

@coroutine
def async_lock(self):
"""
This raises an AlreadyLocked exception if lock() is called
Expand All @@ -217,22 +210,22 @@ def async_lock(self):
if self._lock_obj is not None:
raise self.AlreadyLocked((self._lock_obj,))

async_lock = self._lock_obj = AsynchronousLock(path=self.pkg_path,
result = self.scheduler.create_future()

def acquired_lock(async_lock):
if async_lock.wait() == os.EX_OK:
self.locked = True
result.set_result(None)
else:
result.set_exception(AssertionError(
"AsynchronousLock failed with returncode %s"
% (async_lock.returncode,)))

self._lock_obj = AsynchronousLock(path=self.pkg_path,
scheduler=self.scheduler)
try:
yield async_lock.async_start()
yield async_lock.async_wait()
except asyncio.CancelledError:
if async_lock.poll() is None:
async_lock.cancel()
raise

if async_lock.returncode != os.EX_OK:
raise AssertionError(
"AsynchronousLock failed with returncode %s"
% (async_lock.returncode,))

self.locked = True
self._lock_obj.addExitListener(acquired_lock)
self._lock_obj.start()
return result

class AlreadyLocked(portage.exception.PortageException):
pass
Expand Down
17 changes: 3 additions & 14 deletions lib/_emerge/CompositeTask.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Copyright 1999-2020 Gentoo Authors
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from _emerge.AsynchronousTask import AsynchronousTask
from portage import os
from portage.util.futures import asyncio


class CompositeTask(AsynchronousTask):

Expand Down Expand Up @@ -100,7 +98,7 @@ def _default_final_exit(self, task):
def _start_task(self, task, exit_handler):
"""
Register exit handler for the given task, set it
as self._current_task, and call task.async_start().
as self._current_task, and call task.start().

Subclasses can use this as a generic way to start
a task.
Expand All @@ -112,16 +110,7 @@ def _start_task(self, task, exit_handler):
pass
task.addExitListener(exit_handler)
self._current_task = task
result = asyncio.ensure_future(task.async_start(), loop=self.scheduler)
result.add_done_callback(self._current_task_start_cb)

def _current_task_start_cb(self, future):
try:
future.result()
except asyncio.CancelledError:
self.cancel()
self._was_cancelled()
self._async_wait()
task.start()

def _task_queued(self, task):
task.addStartListener(self._task_queued_start_handler)
Expand Down
Loading