back to Index
2014-07-19
In [2]:
from cogen.core.coroutines import coro
from cogen.core.schedulers import Scheduler
In [4]:
@coro
def a(foo, times):
for i in range(times):
print foo, ':', i
yield
In [5]:
sched=Scheduler()
In [6]:
sched.add(a, args=('foo', 5))
Out[6]:
In [8]:
sched.add(a, args=('bar', 10))
Out[8]:
In [9]:
sched.run()
In [ ]:
import time
import numpy as np
times=np.zeros(shape=[100], dtype=np.float32)
In [49]:
@coro
def time_test(times):
last_time=time.time()
print times
for i in range(100):
now=time.time()
times[0][i]=now-last_time
# print i, times[i]
last_time=now
time.sleep(.01)
yield
In [63]:
times1=np.zeros(shape=[100], dtype=np.float32)
times2=np.zeros(shape=[100], dtype=np.float32)
In [52]:
sched.add?
In [34]:
sched.add(time_test, args=times1)
Out[34]:
In [64]:
sched.add(time_test, args=(times2))
Out[64]:
In [65]:
sched.run()
In [13]:
%matplotlib inline
In [14]:
import matplotlib.pyplot as plt
In [28]:
plt.plot(times2)
plt.xlabel
Out[28]:
In [ ]: