'Shuts down the server from inside it.
Args:
restart (bool or None, optional): True/False sets the
flags so the server will be restarted or not. If None, the
current flag setting (set at initialization or previous
runs) is used.
_reactor_stopping (bool, optional): This is set if server
is already in the process of shutting down; in this case
we don\'t need to stop it again.
Note that restarting (regardless of the setting) will not work
if the Portal is currently running in daemon mode. In that
case it always needs to be restarted manually.'

def shutdown(self, restart=None, _reactor_stopping=False):

    if (_reactor_stopping and hasattr(self, 'shutdown_complete')):
        return
    self.sessions.disconnect_all()
    self.set_restart_mode(restart)
    if ((os.name == 'nt') and os.path.exists(PORTAL_PIDFILE)):
        os.remove(PORTAL_PIDFILE)
    if (not _reactor_stopping):
        self.shutdown_complete = True
        reactor.callLater(0, reactor.stop)
