

def main():
    create_required_directories()
    init_logging()
    log = logging.getLogger(LOGGER_NAME)
    instance = SingleInstance(DAEMON_LOCK_PATH)
    try:
        ui_listener.start()
    except InstanceAlreadyRunning:
        log.info('Daemon: Could not acquire single instance lock. Aborting.')
    else:
        try:
            with open(DAEMON_PID_PATH, 'w') as f:
                f.write(str(os.getpid()))
            monkey.patch_all()
            gevent.spawn(check_own_version, log)
            core_client = CoreClient()
            ui_config = UIConfig()
            notifs_handler = NotificationsHandler()
            ui_listener = UIListener(UI_LISTENER_SOCKET_ADDRESS, core_client, ui_config, notifs_handler)
            core_listener = CoreListener(CORE_LISTENER_SOCKET_ADDRESS, core_client, ui_config, notifs_handler)
            core = Core(core_client)
            core.stop()
            ui_listener_greenlet = gevent.spawn(ui_listener.start)
            core_listener_greenlet = gevent.spawn(core_listener.start)
            watchdog_greenlet = gevent.spawn(core.watchdog)
            Events.shutdown_required.wait()
            log.info('Daemon: Shutting down')
            ui_listener_greenlet.kill(block=True)
            core_listener_greenlet.kill(block=True)
            watchdog_greenlet.kill(block=True)
            try:
                core_client.shutdown()
                gevent.sleep(1)
            except Exception:
                log.warning('Daemon: Gracefull shutdown has thrown an exception.  Will ignore it just shut the core down forcefully.')
            core.stop()
        except Exception:
            log.exception('Daemon: An uncatched error occurred!')
        finally:
            instance.stop()

dataset/ETHPy150Open alticelabs/meocloud-cli/meocloud/client/linux/daemon/daemon.py main/VarMisuse@37/51 `instance`->`ui_listener`