summaryrefslogtreecommitdiffstats
path: root/gamechestcli/gamechest/runners/runnerbase.py
blob: ac64ebb26eb423b35a70e38ed365517c6f2d503e (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
36
37
38
39
40
41
42
43
44
from abc import ABCMeta, abstractmethod


class RunnerBase(metaclass=ABCMeta):

    @abstractmethod
    def get_read_fd(self):
        'fd to select for read evts to know when to progress_read nonblockingly'
        raise NotImplementedError

    @abstractmethod
    def progress_read(self):
        'parse the fd given by get_read_fd and returns current progress'
        raise NotImplementedError

    @abstractmethod
    def terminate(self):
        '''signal runner(s) to cancel immediately the operation, must
        be idempotent if already terminated (not running)'''
        raise NotImplementedError

    @abstractmethod
    def poll(self):
        'returns None if still running, otherwise return returncode'
        raise NotImplementedError

    def close(self):
        'frees resources, clean/unzombify/gc/close-fds, can block if running'

    def __enter__(self):
        'returns self'
        return self

    def __exit__(self, exc_type, value, traceback):
        'terminate and wait garbage-collect'
        self.terminate()
        self.close()


neutral_locale_variables = {
    'LC_ALL':'C.UTF-8',
    'LANG':'C.UTF-8',
    'LANGUAGE':'C.UTF-8',
}