示例#1
0
def main():
    """
    >>> main()  # doctest: +ELLIPSIS
    Task A is going to sleep.
    Task B is sleeping for 10 seconds.
    Task A is awake.
    Task A is going to sleep.
    Task A is awake.
    Task A is going to sleep.
    Task A is awake.
    Task A is going to sleep.
    Task A is awake.
    Task A is going to sleep.
    Task A is awake.
    Task B is awake.
    Idle was called ... times. (Should be >> 1)
    Idle was called 100 times. (Should be 100)

    """
    global idle_count
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.register_idle_func(idle)
    s.run()
    print("Idle was called", idle_count, "times. (Should be >> 1)")
    idle_count = 0
    s.install(task_c())
    s.install(task_d())
    s.run()
    print("Idle was called", idle_count, "times. (Should be 100)")
示例#2
0
  def main(self):
    assert self.setupped

    # Set Up Scheduler
    sched = fibra.schedule()
    self.sched = sched

    # Initialize Tasklets
    info("agent starting")
    sched.install(self.idle())
    sched.install(self.xmit())

    # Load Actors
    info("loading actors")
    for actor in ['actor_core'] + self.config['agent.actors']:
      try:
        self.load_actor(actor)
      except:
        warn("unable to load %s",actor,exc_info=True)
    info("done loading actors")

    # Start Communications
    self.router.start()

    # Run
    try:
      info("agent operational")
      self.sched.run()
      info("agent terminating")
    finally:
      # Shut Down Communications
      self.router.stop()
示例#3
0
def main():
    """
    >>> main()
    256
    Oops, an exception occured.

    """
    schedule = fibra.schedule()
    schedule.debug = True
    schedule.install(main_task())
    schedule.run()
示例#4
0
def test():
    global idle_count
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.register_idle_func(idle)
    s.run()
    print "Idle was called", idle_count, "times. (Should be > 1)"
    idle_count = 0
    s.install(task_c())
    s.install(task_d())
    s.run()
    print "Idle was called", idle_count, "times. (Should be 1)"
示例#5
0
def main():
    """
    >>> main()
    Received: this string is pushed to a waiting task
    Received from Named Tube: this string is pushed into a named tube.

    """
    t = fibra.Tube()
    schedule = fibra.schedule()
    schedule.install(task_a(t))
    schedule.install(task_b(t))
    schedule.install(task_c())
    schedule.install(task_d())
    schedule.run()
示例#6
0
def main():
    """
    >>> main()
    pushed
    pushed
    pushed
    pushed
    pushed
    hello!
    hello!
    hello!
    hello!
    hello!
    """

    schedule = fibra.schedule()
    schedule.install(echo())
    schedule.install(send())
    schedule.install(send())
    schedule.install(send())
    schedule.install(send())
    schedule.install(send())
    schedule.run()
示例#7
0
文件: tasks.py 项目: mfrasca/fibra
def test():
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.run()
示例#8
0
def test():
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.run()
示例#9
0
        while True:
            try:
                line = yield transport.recv_line()
                n = parse_request(line)
                yield transport.send_line("100 SPAM FOLLOWS")
                for i in xrange(n):
                    yield transport.send_line("spam glorious spam")
            except BadRequest:
                yield transport.send_line("400 WE ONLY SERVE SPAM")
    except socket.error:
        pass 
      
class BadRequest(Exception):
    pass
  
def parse_request(line):
    tokens = line.split()
    if len(tokens) != 2 or tokens[0] != "SPAM":
      raise BadRequest
    try:
      n = int(tokens[1])
    except ValueError:
      raise BadRequest
    if n < 1:
      raise BadRequest
    return n

schedule = fibra.schedule()
schedule.install(fibra.net.listen(('localhost', port), handler))
schedule.run()
示例#10
0
文件: tubes.py 项目: mfrasca/fibra
def main():
    t = fibra.Tube()
    schedule = fibra.schedule()
    schedule.install(a(t))
    schedule.install(b(t))
    schedule.run()
示例#11
0
def main():
    s = fibra.schedule()
    #install a task which installs a new task on a new connection
    s.install(fibra.net.listen(("localhost", 2000), task))
    s.run()
示例#12
0
def test():
    schedule = fibra.schedule()
    schedule.install(cat())
    schedule.install(dog())
    schedule.run()
示例#13
0
import logging
logger = logging.getLogger(__name__)

# TODO: after some specified time the status bar should be cleared but not
# too soon, maybe 30 seconds or so but only once the queue is empty, anytime
# something is added to the queue we should set a 30 second timeout to
# check again if the queue is empty and set the status bar message if it's
# empty

# TODO: provide a way to create background tasks that don't call set_busy()

# TODO: check the fibra version here....has to be >0.17 or maybe
# ==0.17 since fibra doesn't seem to ensure any sort of API
# compatibility

schedule = fibra.schedule()

__running = False
__kill = False
__message_ids = None


def running():
    """
    Return True/False if a task is running.
    """
    return __running


def kill():
    """
示例#14
0
文件: sleep.py 项目: mfrasca/fibra
def test():
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.register_idle_func(idle)
    s.run()
示例#15
0
import timeit
import fibra
import random
import sys

scheduler = fibra.schedule()

class hackysacker:
    counter = 0
    def __init__(self,name,circle):
        self.name = name
        self.circle = circle
        circle.append(self)
        self.messageQueue = fibra.Tube()
        scheduler.install(self.messageLoop())

    def messageLoop(self):
        while 1:
            message = yield self.messageQueue.pop()
            if message == "exit":
                return
            kickTo = self.circle[random.randint(0,len(self.circle)-1)]
            hackysacker.counter += 1
            if hackysacker.counter >= turns:
                while self.circle:
                    hs = self.circle.pop()
                    if hs is not self:
                        yield hs.messageQueue.push('exit', wait=True)
            yield kickTo.messageQueue.push(self, wait=True)
                
示例#16
0
文件: nb.py 项目: mfrasca/fibra
def main():
    schedule = fibra.schedule()
    schedule.install(non_blocking_task())
    schedule.install(blocking_task())
    schedule.run()
示例#17
0
def main():
    schedule = fibra.schedule()
    schedule.install(fibra.net.listen(('localhost', port), handler))
    schedule.run()
示例#18
0
def test():
    schedule = fibra.schedule()
    schedule.install(cat())
    schedule.install(dog())
    schedule.run()
示例#19
0
import timeit
import fibra
import random
import sys

scheduler = fibra.schedule()


class hackysacker:
    counter = 0

    def __init__(self, name, circle):
        self.name = name
        self.circle = circle
        circle.append(self)
        self.messageQueue = fibra.Tube()
        scheduler.install(self.messageLoop())

    def messageLoop(self):
        while 1:
            message = yield self.messageQueue.pop()
            if message == "exit":
                return
            kickTo = self.circle[random.randint(0, len(self.circle) - 1)]
            hackysacker.counter += 1
            if hackysacker.counter >= turns:
                while self.circle:
                    hs = self.circle.pop()
                    if hs is not self:
                        yield hs.messageQueue.push('exit', wait=True)
            yield kickTo.messageQueue.push(self, wait=True)
示例#20
0
def test():
    s = fibra.schedule()
    s.install(task_a())
    s.install(task_b())
    s.register_idle_func(idle)
    s.run()