Ejemplo n.º 1
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True
            scheduler.schedule(action)

            yield from asyncio.sleep(0.1, loop=loop)
            assert(ran == True)
Ejemplo n.º 2
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True
            scheduler.schedule(action)

            yield from asyncio.sleep(0.1, loop=loop)
            assert(ran is True)
Ejemplo n.º 3
0
        def go():
            scheduler = AsyncIOScheduler(loop)

            ran = [False]

            def action(scheduler, state):
                ran[0] = True

            scheduler.schedule(action)

            yield From(asyncio.sleep(0.1, loop=loop))
            assert(ran[0] is True)
Ejemplo n.º 4
0
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop)

            def action(scheduler, state):
                nonlocal ran
                ran = True
            d = scheduler.schedule_relative(10, action)
            d.dispose()

            yield from asyncio.sleep(0.1, loop=loop)
            assert(not ran)
Ejemplo n.º 5
0
        def go():
            scheduler = AsyncIOScheduler(loop)

            ran = [False]

            def action(scheduler, state):
                ran[0] = True

            scheduler.schedule(action)

            yield From(asyncio.sleep(0.1, loop=loop))
            assert (ran[0] is True)
Ejemplo n.º 6
0
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop)

            def action(scheduler, state):
                nonlocal ran
                ran = True
            d = scheduler.schedule_relative(0.01, action)
            d.dispose()

            yield from asyncio.sleep(0.1, loop=loop)
            assert(not ran)
Ejemplo n.º 7
0
        def go():
            scheduler = AsyncIOScheduler(loop)

            ran = [False]

            def action(scheduler, state):
                ran[0] = True

            d = scheduler.schedule_relative(10, action)
            d.dispose()

            yield From(asyncio.sleep(0.1, loop=loop))
            assert(not ran[0])
Ejemplo n.º 8
0
        def go():
            scheduler = AsyncIOScheduler(loop)

            ran = [False]

            def action(scheduler, state):
                ran[0] = True

            d = scheduler.schedule_relative(10, action)
            d.dispose()

            yield From(asyncio.sleep(0.1, loop=loop))
            assert (not ran[0])
Ejemplo n.º 9
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()

            endtime = [None]

            def action(scheduler, state):
                endtime[0] = loop.time()

            scheduler.schedule_relative(200, action)

            yield From(asyncio.sleep(0.3, loop=loop))
            diff = endtime[0] - starttime
            assert(diff > 0.18)
Ejemplo n.º 10
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            scheduler.schedule_relative(200, action)

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime-starttime
            assert(diff > 0.18)
Ejemplo n.º 11
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()

            endtime = [None]

            def action(scheduler, state):
                endtime[0] = loop.time()

            scheduler.schedule_relative(200, action)

            yield From(asyncio.sleep(0.3, loop=loop))
            diff = endtime[0] - starttime
            assert (diff > 0.18)
Ejemplo n.º 12
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            scheduler.schedule_relative(0.2, action)

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime-starttime
            assert(diff > 0.18)
Ejemplo n.º 13
0
def go():
    scheduler = AsyncIOScheduler()

    xs = Observable.from_([x for x in range(10)], scheduler=scheduler)
    gen = xs.to_async_generator()

    # Wish we could write something like:
    # ys = (x for x in yield from gen())
    while True:
        x = yield from gen()
        if x is None:
            break
        print(x)
def run(interval, port):
    scheduler = AsyncIOScheduler()
    clock = Observable.timer(0, interval, scheduler=scheduler)
    loop = asyncio.get_event_loop()
    server = TCPServer(loop)
    observer = SimpleObserver()

    all_events = server.tcp_subject.map(lambda x: x[0].strip()).merge(
        clock).debounce(int(interval / 10), scheduler=scheduler)
    all_events.subscribe(observer)

    server.start(port)
    loop.close()
Ejemplo n.º 15
0
        def go():
            scheduler = AsyncIOScheduler(loop, threadsafe=True)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True

            def schedule():
                scheduler.schedule(action)

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.1, loop=loop)
            assert (ran is True)
Ejemplo n.º 16
0
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop, threadsafe=True)

            def action(scheduler, state):
                nonlocal ran
                ran = True

            def schedule():
                d = scheduler.schedule_relative(10, action)
                d.dispose()

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.1, loop=loop)
            assert (not ran)
Ejemplo n.º 17
0
        def go():
            scheduler = AsyncIOScheduler(loop, threadsafe=True)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            def schedule():
                scheduler.schedule_relative(200, action)

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime - starttime
            assert (diff > 0.18)
Ejemplo n.º 18
0
    def __init__(self, app, interval=1800, buffer_size=20):
        self.app = app
        self.is_running = False
        self.interval = interval
        self.logger = logging.getLogger("AutomatonRunner")
        self.pool = ThreadPoolExecutor()
        self.logging_queue = queue.Queue(-1)

        self.logger.addHandler(QueueHandler(self.logging_queue))

        pool_scheduler = AsyncIOScheduler()
        self.log_source = ReplaySubject(buffer_size=buffer_size,
                                        scheduler=pool_scheduler)
        logging_handler = LoggingRxHandler(self.log_source)
        logging_handler.setFormatter(
            logging.Formatter(
                '\033[34m%(asctime)s \033[91m%(name)s\033[0m %(message)s'))
        self.logging_queue_listener = QueueListener(self.logging_queue,
                                                    logging_handler)
        self.logging_queue_listener.start()
Ejemplo n.º 19
0
 def test_asyncio_schedule_now(self):
     loop = asyncio.get_event_loop()
     scheduler = AsyncIOScheduler(loop)
     res = scheduler.now() - datetime.now()
     assert(res < timedelta(seconds=1))
Ejemplo n.º 20
0
async def go():
    scheduler = AsyncIOScheduler()

    async for x in Observable.range(0, 10, scheduler=scheduler):
        print("got %s" % x)
Ejemplo n.º 21
0
from rx import Observable
from rx.concurrency import AsyncIOScheduler

from cyclotron import Component
from cyclotron.router import make_error_router

from cyclotron_aio.runner import run
import cyclotron_aio.httpd as httpd
import cyclotron_std.sys.argv as argv
import cyclotron_std.io.file as file
import cyclotron_std.argparse as argparse
import cyclotron_std.logging as logging

import deepspeech_server.deepspeech as deepspeech

aio_scheduler = AsyncIOScheduler()

DeepspeechSink = namedtuple('DeepspeechSink',
                            ['logging', 'deepspeech', 'httpd', 'file'])
DeepspeechSource = namedtuple(
    'DeepspeechSource', ['deepspeech', 'httpd', 'logging', 'file', 'argv'])
DeepspeechDrivers = namedtuple(
    'DeepspeechServerDrivers',
    ['logging', 'deepspeech', 'httpd', 'file', 'argv'])


def parse_config(config_data):
    ''' takes a stream with the content of the configuration file as input
    and returns a (hot) stream of arguments .
    '''
    config = (
Ejemplo n.º 22
0
 def test_asyncio_schedule_now(self):
     loop = asyncio.get_event_loop()
     scheduler = AsyncIOScheduler(loop)
     res = scheduler.now - datetime.now()
     assert(res < timedelta(seconds=1))
Ejemplo n.º 23
0
from rx.subjects import Subject
from rx.concurrency import QtScheduler, AsyncIOScheduler

from client.client import Client
from client.client_window import ClientWindow

import utils

if __name__ == '__main__':
    app = QApplication(sys.argv)
    scheduler = QtScheduler(QtCore)
    stock_prices = Subject()
    client = Client(port='9999')

    loop = asyncio.new_event_loop()
    asyncio_scheduler = AsyncIOScheduler(loop)

    def run_client():
        asyncio.set_event_loop(loop)
        asyncio.get_event_loop().call_soon(utils.run_client_websocket, client,
                                           stock_prices)
        asyncio.get_event_loop().run_forever()

    thread = Thread(target=run_client, daemon=True)
    thread.start()

    client_window = ClientWindow(stock_prices_stream=stock_prices)

    def send_order(order):
        stock_order = {
            'stock_symbol': order['symbol'],