Skip to content
This repository
Browse code

Example updates.

  • Loading branch information...
commit 90f0b256a1fba9ea596d8b124a2e69d802f4a5e6 1 parent 8883f97
Jamie Turner authored September 16, 2010
21  examples/event.py
... ...
@@ -0,0 +1,21 @@
  1
+from diesel.util.event import Event
  2
+from diesel import quickstart, quickstop, sleep
  3
+
  4
+pistol = Event()
  5
+
  6
+def racer():
  7
+    pistol.wait()
  8
+    print "CHAAARGE!"
  9
+
  10
+def starter():
  11
+    print "Ready..."
  12
+    sleep(1)
  13
+    print "Set..."
  14
+    sleep(1)
  15
+    print " ~~~~~~~~~ BANG ~~~~~~~~~ "
  16
+    pistol.set()
  17
+    sleep(1)
  18
+    print " ~~~~~~~~~ RACE OVER ~~~~~~~~~ "
  19
+    quickstop()
  20
+
  21
+quickstart(starter, [racer for x in xrange(8)])
36  examples/queue.py
... ...
@@ -1,45 +1,35 @@
1 1
 from diesel.util.queue import Queue, QueueTimeout
2  
-from diesel import log as glog, Application, Loop, sleep
  2
+from diesel.util.event import Countdown
  3
+from diesel import log as glog, sleep, quickstart, quickstop
3 4
 
4 5
 q = Queue()
  6
+cd = Countdown(4)
5 7
 
6 8
 def putter():
7 9
     log = glog.sublog("putter", glog.info)
8 10
     
9  
-    log.info("putting 50000 things on log")
10  
-    for x in xrange(50000):
11  
-        q.put(x)
12  
-        sleep()
13  
-
14  
-    log.info("done, sleeping for 10s...")
15  
-
16  
-    sleep(10)
17  
-
18  
-    log.info("putting 50000 *more* things on log")
19  
-    for x in xrange(50000, 100000):
  11
+    log.info("putting 100000 things on log")
  12
+    for x in xrange(100000):
20 13
         q.put(x)
21 14
         sleep()
22 15
 
23 16
 def getter():
24 17
     log = glog.sublog("getter", glog.info)
25 18
     got = 0
26  
-    while got < 100000:
  19
+    while got < 25000:
27 20
         try:
28 21
             s = q.get(timeout=3)
  22
+            sleep()
29 23
         except QueueTimeout:
30 24
             log.warn("timeout before getting a value, retrying...")
31 25
             continue
32  
-        assert s == got
33 26
         got += 1
34 27
 
35  
-        if got % 10000 == 0:
36  
-            log.info("up to %s received, sleeping for 0.5s" % got)
37  
-            sleep(0.5)
  28
+    log.info("SUCCESS!  got all 25,000")
  29
+    cd.tick()
38 30
 
39  
-    log.info("SUCCESS!  got all 100,000")
40  
-    a.halt()
  31
+def manage():
  32
+    cd.wait()
  33
+    quickstop()
41 34
 
42  
-a = Application()
43  
-a.add_loop(Loop(putter))
44  
-a.add_loop(Loop(getter))
45  
-a.run()
  35
+quickstart(manage, putter, [getter for x in xrange(4)])
1  examples/synchronized.py
@@ -13,7 +13,6 @@ def free_loop():
13 13
 
14 14
 def sync_loop():
15 15
     global sync
16  
-    id = random.random()
17 16
     with synchronized():
18 17
         sync += 1
19 18
         sleep(random.random())

0 notes on commit 90f0b25

Please sign in to comment.
Something went wrong with that request. Please try again.