Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamie Turner
committed
Sep 17, 2010
1 parent
8883f97
commit 90f0b25
Showing
3 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from diesel.util.event import Event | ||
from diesel import quickstart, quickstop, sleep | ||
|
||
pistol = Event() | ||
|
||
def racer(): | ||
pistol.wait() | ||
print "CHAAARGE!" | ||
|
||
def starter(): | ||
print "Ready..." | ||
sleep(1) | ||
print "Set..." | ||
sleep(1) | ||
print " ~~~~~~~~~ BANG ~~~~~~~~~ " | ||
pistol.set() | ||
sleep(1) | ||
print " ~~~~~~~~~ RACE OVER ~~~~~~~~~ " | ||
quickstop() | ||
|
||
quickstart(starter, [racer for x in xrange(8)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,35 @@ | ||
from diesel.util.queue import Queue, QueueTimeout | ||
from diesel import log as glog, Application, Loop, sleep | ||
from diesel.util.event import Countdown | ||
from diesel import log as glog, sleep, quickstart, quickstop | ||
|
||
q = Queue() | ||
cd = Countdown(4) | ||
|
||
def putter(): | ||
log = glog.sublog("putter", glog.info) | ||
|
||
log.info("putting 50000 things on log") | ||
for x in xrange(50000): | ||
q.put(x) | ||
sleep() | ||
|
||
log.info("done, sleeping for 10s...") | ||
|
||
sleep(10) | ||
|
||
log.info("putting 50000 *more* things on log") | ||
for x in xrange(50000, 100000): | ||
log.info("putting 100000 things on log") | ||
for x in xrange(100000): | ||
q.put(x) | ||
sleep() | ||
|
||
def getter(): | ||
log = glog.sublog("getter", glog.info) | ||
got = 0 | ||
while got < 100000: | ||
while got < 25000: | ||
try: | ||
s = q.get(timeout=3) | ||
sleep() | ||
except QueueTimeout: | ||
log.warn("timeout before getting a value, retrying...") | ||
continue | ||
assert s == got | ||
got += 1 | ||
|
||
if got % 10000 == 0: | ||
log.info("up to %s received, sleeping for 0.5s" % got) | ||
sleep(0.5) | ||
log.info("SUCCESS! got all 25,000") | ||
cd.tick() | ||
|
||
log.info("SUCCESS! got all 100,000") | ||
a.halt() | ||
def manage(): | ||
cd.wait() | ||
quickstop() | ||
|
||
a = Application() | ||
a.add_loop(Loop(putter)) | ||
a.add_loop(Loop(getter)) | ||
a.run() | ||
quickstart(manage, putter, [getter for x in xrange(4)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters