Esempio n. 1
0
by_now = lambda x,y: x.now < y.now
by_priority = lambda x,y: x.priority > y.priority

timeline = ContainerStack()
timeline.add_layer(container=BatchHeap(by_now),
                   get=BatchHeap.pop,
                   put=BatchHeap.push,
                   broker=events2waiters
                   )
timeline.add_layer(container=BatchHeap(by_priority),
                   get=BatchHeap.pop,
                   put=BatchHeap.push
                   )
timeline.add_layer(container=deque(),
                   get=deque.popleft,
                   put=deque.extend
                   )

thread_f = Thread('f', 0)
thread_g = Thread('g', 1)
thread_h = Thread('h', 1)
timeline.put(Event('Initial', 0, [thread_f]))
timeline.put(Event('Initial', 0, [thread_g]))
timeline.put(Event('Initial', 0, [thread_h]))
timeline.put(Event('Timeout', 1, [thread_f, thread_g]))

loop(step_thread)
#loop(step_same_priorty)
#loop(step_same_now)
Esempio n. 2
0

def step_same_now():
    print timeline.get(depth=2)


by_now = lambda x, y: x.now < y.now
by_priority = lambda x, y: x.priority > y.priority

timeline = ContainerStack()
timeline.add_layer(container=BatchHeap(by_now),
                   get=BatchHeap.pop,
                   put=BatchHeap.push,
                   broker=events2waiters)
timeline.add_layer(container=BatchHeap(by_priority),
                   get=BatchHeap.pop,
                   put=BatchHeap.push)
timeline.add_layer(container=deque(), get=deque.popleft, put=deque.extend)

thread_f = Thread('f', 0)
thread_g = Thread('g', 1)
thread_h = Thread('h', 1)
timeline.put(Event('Initial', 0, [thread_f]))
timeline.put(Event('Initial', 0, [thread_g]))
timeline.put(Event('Initial', 0, [thread_h]))
timeline.put(Event('Timeout', 1, [thread_f, thread_g]))

loop(step_thread)
#loop(step_same_priorty)
#loop(step_same_now)