blob: 0cd034c9718f9c60fdaf43d14d9bcb85a0f6fb72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# Copyright 2018-2021 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import os
import signal
from _emerge.AsynchronousTask import AsynchronousTask
from portage.util.futures import asyncio
class AsyncTaskFuture(AsynchronousTask):
"""
Wraps a Future in an AsynchronousTask, which is useful for
scheduling with TaskScheduler.
"""
__slots__ = ("future",)
def _start(self):
self.future = asyncio.ensure_future(self.future, self.scheduler)
self.future.add_done_callback(self._done_callback)
def _cancel(self):
if not self.future.done():
self.future.cancel()
def _done_callback(self, future):
if future.cancelled():
self.cancelled = True
self.returncode = -signal.SIGINT
elif future.exception() is None:
self.returncode = os.EX_OK
else:
self.returncode = 1
self._async_wait()
|