#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

class Backend(object):
    def __init__ (self, router):
        self.router = router
    
    def log(self, level, message):
        self.router.log(level, message)

    def start(self):
        raise NotImplementedError
    
    def stop(self):
        raise NotImplementedError
    
    def send(self):
        raise NotImplementedError
    
    def receive(self):
        raise NotImplementedError

#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

class Backend(object):
    def __init__ (self, router):
        self.router = router
        self.running = False
    
    def log(self, level, message):
        self.router.log(level, message)

    def start(self):
        self.running = True
        try:
            self.run()
        finally:
            self.running = False

    def run (self):
        raise NotImplementedError
    
    def stop(self):
        self.running = False
    
    def send(self):
        raise NotImplementedError
    
    def receive(self):
        raise NotImplementedError

Add run() method to Backend and make start() a wrapper for it. Also set backend.running in backend.start and backend.stop. Whatever code runs in a loop in backend.run() needs to check self.running periodically to make sure it should still be running.