# Buggy code
def main():
    """Main entry point for Glances.

    Select the mode (standalone, client or server)
    Run it...
    """
    # Log Glances and PSutil version
    logger.info("Start Glances {}".format(__version__))
    logger.info(
        "{} {} and PSutil {} detected".format(
            platform.python_implementation(), platform.python_version(), psutil_version
        )
    )

    # Share global var
    global core

    # Create the Glances main instance
    core = GlancesMain()
    config = core.get_config()
    args = core.get_args()

    # Catch the CTRL-C signal
    signal.signal(signal.SIGINT, __signal_handler)

    # Glances can be ran in standalone, client or server mode
    if core.is_standalone():
        start_standalone(config=config, args=args)
    elif core.is_client() and not WINDOWS:
        if core.is_client_browser():
            start_clientbrowser(config=config, args=args)
        else:
            start_client(config=config, args=args)
    elif core.is_server():
        start_server(config=config, args=args)
    elif core.is_webserver():
        # Web server mode replace the standalone mode on Windows OS
        # In this case, try to start the web browser mode automaticaly
        if WINDOWS:
            args.open_web_browser = True
        start_webserver(config=config, args=args)


# Traceback (NameError)
C:\Windows\system32>glances
Glances web server started on http://0.0.0.0:61209/
Traceback (most recent call last):
File "C:\Python27\Scripts\glances-script.py", line 11, in <module>
load_entry_point('Glances==2.8.2', 'console_scripts', 'glances')()
File "c:\python27\lib\site-packages\glances\__init__.py", line 238, in main
start_webserver(config=config, args=args)
File "c:\python27\lib\site-packages\glances\__init__.py", line 196, in start_webserver
webserver.serve_forever()
File "c:\python27\lib\site-packages\glances\webserver.py", line 48, in serve_forever
self.web.start(self.stats)
File "c:\python27\lib\site-packages\glances\outputs\glances_bottle.py", line 148, in start
self._app.run(host=self.args.bind_address, port=self.args.port, quiet=not self.args.debug)
File "C:\Python27\Scripts\bottle.py", line 755, in run
run(self, **kwargs)
File "C:\Python27\Scripts\bottle.py", line 3127, in run
server.run(app)
File "C:\Python27\Scripts\bottle.py", line 2782, in run
srv.serve_forever()
File "c:\python27\lib\SocketServer.py", line 231, in serve_forever
poll_interval)
File "c:\python27\lib\SocketServer.py", line 150, in _eintr_retry
return func(*args)
File "c:\python27\lib\site-packages\glances\__init__.py", line 68, in __signal_handler
end()
File "c:\python27\lib\site-packages\glances\__init__.py", line 75, in end
standalone.end()
NameError: global name 'standalone' is not defined

# Fixed code
def main():
    """Main entry point for Glances.

    Select the mode (standalone, client or server)
    Run it...
    """
    # Log Glances and PSutil version
    logger.info("Start Glances {}".format(__version__))
    logger.info(
        "{} {} and PSutil {} detected".format(
            platform.python_implementation(), platform.python_version(), psutil_version
        )
    )

    # Share global var
    global core

    # Create the Glances main instance
    core = GlancesMain()
    config = core.get_config()
    args = core.get_args()

    # Catch the CTRL-C signal
    signal.signal(signal.SIGINT, __signal_handler)

    # Glances can be ran in standalone, client or server mode
    if core.is_standalone() and not WINDOWS:
        start_standalone(config=config, args=args)
    elif core.is_client() and not WINDOWS:
        if core.is_client_browser():
            start_clientbrowser(config=config, args=args)
        else:
            start_client(config=config, args=args)
    elif core.is_server():
        start_server(config=config, args=args)
    elif core.is_webserver():
        # Web server mode replace the standalone mode on Windows OS
        start_webserver(config=config, args=args)