Esempio n. 1
0
def exit_sequence(name, id, queue_task):
    sequence = sequences[name]
    section = sequence.popleft()
    assert section['id'] == id
    if sequence:
        queue_task(0, sequence[0]['deferred'].callback, sequence[0]['id'])
    else:
        sequences.pop(name)
Esempio n. 2
0
 def wait_for_input():
     try:
         prompt = ">>> "
         if source:
             prompt = "... "
         s = ic.raw_input(prompt)
     except EOFError:
         eventloop.queue_task(0, eventloop.halt)
         return
     eventloop.queue_task(0, cb, s)
Esempio n. 3
0
 def wait_for_input():
     try:
         prompt = ">>> "
         if source:
             prompt = "... "
         s = ic.raw_input(prompt)
     except EOFError:
         eventloop.queue_task(0, eventloop.halt)
         return
     eventloop.queue_task(0, cb, s)
Esempio n. 4
0
 def test_read_some_delay(self):
     data = 'ok'
     self.conn.timeout = 0.2
     def populate():
         self.buffer = data
         self.stack_conn.read_cb(None)
     eventloop.queue_task(0.1, populate)
     r = yield self.conn.read_some()
     self.assertEqual(r, data)
     self.assertEqual(self.stack_conn.resume_called, 1)
     yield sleep(0.2)  # ensure timeout has expired
Esempio n. 5
0
 def test_read_delay(self):
     data = 'ok'
     self.buffer = 'o'
     self.conn.timeout = 0.2
     def populate():
         self.buffer += 'k'
         self.stack_conn.read_cb(None)
     eventloop.queue_task(0.1, populate)
     r = yield self.conn.read(2)
     assert r == data
     assert self.stack_conn.resume_called == 1
     yield sleep(0.2)  # ensure timeout has expired
Esempio n. 6
0
    def test_read_some_delay(self):
        data = 'ok'
        self.conn.timeout = 0.2

        def populate():
            self.buffer = data
            self.stack_conn.read_cb(None)

        eventloop.queue_task(0.1, populate)
        r = yield self.conn.read_some()
        self.assertEqual(r, data)
        self.assertEqual(self.stack_conn.resume_called, 1)
        yield sleep(0.2)  # ensure timeout has expired
Esempio n. 7
0
 def send(self, value):
     if self._recv_cbs:
         # if there are receivers waiting, send to the first one
         rcb = self._recv_cbs.popleft()
         queue_task(0, rcb, value)
     elif len(self._msgs) < self.bufsize:
         # if there's available buffer, use that
         self._msgs.append(value)
     else:
         # otherwise, wait for a receiver
         cb = Callback()
         self._send_cbs.append(cb)
         rcb = yield cb
         queue_task(0, rcb, value)
Esempio n. 8
0
 def send(self, value):
     if self._recv_cbs:
         # if there are receivers waiting, send to the first one
         rcb = self._recv_cbs.popleft()
         queue_task(0, rcb, value)
     elif len(self._msgs) < self.bufsize:
         # if there's available buffer, use that
         self._msgs.append(value)
     else:
         # otherwise, wait for a receiver
         cb = Callback()
         self._send_cbs.append(cb)
         rcb = yield cb
         queue_task(0, rcb, value)
Esempio n. 9
0
    def test_read_delay(self):
        data = 'ok'
        self.buffer = 'o'
        self.conn.timeout = 0.2

        def populate():
            self.buffer += 'k'
            self.stack_conn.read_cb(None)

        eventloop.queue_task(0.1, populate)
        r = yield self.conn.read(2)
        assert r == data
        assert self.stack_conn.resume_called == 1
        yield sleep(0.2)  # ensure timeout has expired
Esempio n. 10
0
    def fire(self, value):
        if not self._wait_df:
            if len(self._msgs) >= self.bufsize:
                if not self._fire_df:
                    self._fire_df = Deferred()
                yield self._fire_df

        if not self._wait_df:
            assert (len(self._msgs) < self.bufsize)
            self._msgs.append(value)
            return

        assert(len(self._msgs) == 0)
        df = self._wait_df
        self._wait_df = None
        queue_task(0, df.callback, value)
Esempio n. 11
0
 def _queue_timeout(self, cb):
     if self.timeout is not None:
         if self._current_timeout:
             self._current_timeout.cancel()
         self._current_timeout = evlp.queue_task(self.timeout,
                                                 self._time_out, cb,
                                                 self.timeout)
Esempio n. 12
0
 def _queue_timeout(self, cb):
     if self.timeout is not None:
         if self._current_timeout:
             self._current_timeout.cancel()
         self._current_timeout = evlp.queue_task(self.timeout,
                                                 self._time_out,
                                                 cb,
                                                 self.timeout)
Esempio n. 13
0
    def wait(self):
        popped = False
        if self._msgs:
            value = self._msgs.popleft()
            popped = True

        if not self._wait_df:
            self._wait_df = Deferred()
        wait_df = self._wait_df

        if self._fire_df:
            df = self._fire_df
            self._fire_df = None
            queue_task(0, df.callback, None)

        if not popped:
            value = yield wait_df
        yield value
Esempio n. 14
0
    return fifth()


@_o
def third():
    yield fourth()


def second():
    return third()


@_o
def first():
    yield second()


@_o
def first_evlp():
    try:
        yield sleep(1)
        yield req()
        yield launch(second)
    finally:
        eventloop.halt()


launch(first)
eventloop.queue_task(0, first_evlp)
eventloop.run()
Esempio n. 15
0
import sys

import monocle
from monocle import _o
monocle.init(sys.argv[1])

from monocle.stack import eventloop
from monocle.util import sleep


@_o
def foo(x, z=1):
    yield sleep(1)
    print x


def bar(x, z=1):
    print x


@_o
def fail():
    raise Exception("whoo")
    yield sleep(1)


eventloop.queue_task(0, foo, x="oroutine worked")
eventloop.queue_task(0, bar, x="function worked")
eventloop.queue_task(0, fail)
eventloop.run()
Esempio n. 16
0
File: util.py Progetto: sah/monocle
def sleep(seconds):
    cb = Callback()
    queue_task(seconds, cb, None)
    return cb
Esempio n. 17
0
File: util.py Progetto: sah/monocle
def delayed(seconds, val):
    cb = Callback()
    queue_task(seconds, cb, val)
    return cb
Esempio n. 18
0
def delayed(seconds, val):
    cb = Callback()
    queue_task(seconds, cb, val)
    return cb
Esempio n. 19
0
File: util.py Progetto: mgax/monocle
def sleep(seconds):
    d = Deferred()
    queue_task(seconds, d.callback, None)
    return d
Esempio n. 20
0
import monocle

from monocle import _o
monocle.init(sys.argv[1])

from monocle.stack import eventloop
from monocle.util import sleep


@_o
def yielding_oroutine(x, z=1):
    yield sleep(1)
    print x


def nonyielding_oroutine(x, z=1):
    print x


@_o
def fail():
    raise Exception("whoo")
    yield sleep(1)


eventloop.queue_task(0, yielding_oroutine, x="oroutine worked")
eventloop.queue_task(0, nonyielding_oroutine, x="function worked")
eventloop.queue_task(0, fail)
eventloop.run()
Esempio n. 21
0
import monocle

from monocle import _o
monocle.init(sys.argv[1])

from monocle.stack import eventloop
from monocle.util import sleep


@_o
def yielding_oroutine(x, z=1):
    yield sleep(1)
    print(x)


def nonyielding_oroutine(x, z=1):
    print(x)


@_o
def fail():
    raise Exception("whoo")
    yield sleep(1)


eventloop.queue_task(0, yielding_oroutine, x="oroutine worked")
eventloop.queue_task(0, nonyielding_oroutine, x="function worked")
eventloop.queue_task(0, fail)
eventloop.run()
Esempio n. 22
0
 def proc_wrapper():
     eventloop.queue_task(0, target, *args, **kwargs)
     eventloop.run()
Esempio n. 23
0
def sleep(seconds):
    cb = Callback()
    queue_task(seconds, cb, None)
    return cb
Esempio n. 24
0
import sys

import monocle
from monocle import _o
monocle.init(sys.argv[1])

from monocle.stack import eventloop
from monocle.util import sleep

@_o
def foo(x, z=1):
    yield sleep(1)
    print x

def bar(x, z=1):
    print x

@_o
def fail():
    raise Exception("whoo")
    yield sleep(1)

eventloop.queue_task(0, foo, x="oroutine worked")
eventloop.queue_task(0, bar, x="function worked")
eventloop.queue_task(0, fail)
eventloop.run()
Esempio n. 25
0
 def proc_wrapper():
     eventloop.queue_task(0, target, *args, **kwargs)
     eventloop.run()
Esempio n. 26
0
  die()

def fourth():
  return fifth()

@_o
def third():
  yield fourth()

def second():
  return third()

@_o
def first():
  yield second()

@_o
def first_evlp():
  try:
    yield sleep(1)
    yield req()
    yield launch(second)
  finally:
    eventloop.halt()

launch(first)
eventloop.queue_task(0, first_evlp)
eventloop.run()