How to use the twisted.internet.reactor.stop function in Twisted

To help you get started, we’ve selected a few Twisted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github privcount / privcount / privcount / log.py View on Github external
def stop_reactor(exit_code=0):
    '''
    Stop the reactor and exit with exit_code.
    If exit_code is None, don't exit, just return to the caller.
    exit_code must be between 1 and 255.
    '''
    if exit_code is not None:
        logging.warning("Exiting with code {}".format(exit_code))
    else:
        # Let's hope the calling code exits pretty soon after this
        logging.warning("Stopping reactor")

    try:
        reactor.stop()
    except ReactorNotRunning:
        pass

    # return to the caller and let it decide what to do
    if exit_code == None:
        return

    # a graceful exit
    if exit_code == 0:
        sys.exit()

    # a hard exit
    assert exit_code >= 0
    assert exit_code <= 127
    os._exit(exit_code)
github twisted / twisted / src / twisted / conch / scripts / tkconch.py View on Github external
def gotChar(ch, resp=resp):
        if not ch: return
        if ch=='\x03': # C-c
            reactor.stop()
        if ch=='\r':
            frame.write('\r\n')
            stresp = ''.join(resp)
            del resp
            frame.callback = None
            d.callback(stresp)
            return
        elif 32 <= ord(ch) < 127:
            resp.append(ch)
            if echo:
                frame.write(ch)
        elif ord(ch) == 8 and resp: # BS
            if echo: frame.write('\x08 \x08')
            resp.pop()
    frame.callback = gotChar
github warner / foolscap / doc / listings / command-client.py View on Github external
def _failure(res):
    reactor.stop()
    print res
    return -1
d.addCallbacks(_success, _failure)
github rstms / txTrader / txtrader / rtx.py View on Github external
def force_disconnect(self, reason):
        self.update_connection_status('Disconnected')
        self.error_handler(self.id, 'API Disconnect: %s' % reason)
        reactor.stop()
github EricssonResearch / calvin-base / calvin / runtime / south / storage / twistedimpl / securedht / dht_server.py View on Github external
print a.set(key="APA", value="banan")

        print a.get(key="APA")
        print b.get(key="APA")

        a.stop()
        b.stop()

    except:
        traceback.print_exc()
        ret = 1

    finally:
        if reactor.running:
            threads.blockingCallFromThread(reactor, reactor.stop)

    return ret
github labrad / pylabrad / labrad / util / __init__.py View on Github external
def run(srv):
        host = config['host']
        port = int(config['port'])
        tls_mode = config['tls']
        try:
            p = yield protocol.connect(host, port, tls_mode, config['username'],
                                       config['password'])
            yield srv.startup(p)
            yield srv.onShutdown()
            log.msg('Disconnected cleanly.')
        except Exception as e:
            log.msg('There was an error: {}'.format(e))
        if stop_reactor:
            try:
                reactor.stop()
            except Exception:
                pass
github crossbario / iotcookbook / device / pi / components / _work / light_sensor / app / client.py View on Github external
def onDisconnect(self):
        self.log.info("connection closed")
        try:
            reactor.stop()
        except ReactorNotRunning:
            pass
github cedricholz / Twitter-Crypto-Signal-Binance-Bot / limit_strategy.py View on Github external
cur_price = float(msg['p'])

        percent_from_max = utils.percent_change(max_price, cur_price)
        percent_from_bought = utils.percent_change(price_bought, cur_price)

        # COMMENT THIS LINE OUT IF YOU DON'T WANT TOO MUCH DATA
        print_trade_data(price_bought, cur_price, max_price, percent_from_max, percent_from_bought)

        if reached_goal == False and percent_from_bought >= sell_order_desired_percentage_profit:
            reached_goal = True
            utils.print_and_write_to_logfile("REACHED PRICE GOAL")

        if percent_from_max < sell_percent_down_to_sell and reached_goal == True:
            utils.print_and_write_to_logfile("PERCENT DOWN FROM PEAK: " + str(percent_from_max) + ". TIME TO SELL")
            try:
                reactor.stop()
            except:
                print("REACTOR ALREADY STOPPED")

        max_price = max(cur_price, max_price)