Code Duplication    Length = 17-20 lines in 2 locations

grimreaper.py 2 locations

@@ 61-80 (lines=20) @@
58
    def _close(self):
59
        self._socket.close()
60
61
    def register(self, timeout=None, pid=None):
62
        if timeout is None:
63
            timeout = self._process_timeout
64
65
        if pid is None:
66
            pid = os.getpid()
67
68
        if self._is_connected():
69
            msg = 'register:%s:%s' % (pid, timeout)
70
            try:
71
                self._socket.sendall(msg.encode('utf-8'))
72
            except socket.error as e:
73
                if e.errno == socket.errno.EPIPE:
74
                    self._close()
75
                    return
76
                log.debug(e)
77
78
            log.debug('Registered process (PID=%s; timeout=%s)', pid, timeout)
79
        else:
80
            log.warning('Unable to register the process (PID=%s).', pid)
81
82
    def unregister(self, pid=None):
83
        if pid is None:
@@ 82-98 (lines=17) @@
79
        else:
80
            log.warning('Unable to register the process (PID=%s).', pid)
81
82
    def unregister(self, pid=None):
83
        if pid is None:
84
            pid = os.getpid()
85
86
        if self._is_connected():
87
            msg = 'unregister:%s' % pid
88
            try:
89
                self._socket.sendall(msg.encode('utf-8'))
90
            except socket.error as e:
91
                if e.errno == socket.errno.EPIPE:
92
                    self._close()
93
                    return
94
                log.debug(e)
95
96
            log.debug('Unregistered process (PID=%s)', pid)
97
        else:
98
            log.warning('Unable to unregister the process (PID=%s).', pid)
99
100
    def on_connection_error(self, exc):
101
        pass