public
Description: my public development respository
Homepage:
Clone URL: git://github.com/evanlong/evan-public-development.git
100644 64 lines (47 sloc) 1.26 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Evan Long
#Copyright 2009
 
from __future__ import with_statement
import threading
import time
 
prop = {
    'rpm':8
}
 
gun = {
    'rounds':20,
    'rate':1,
    'tracer_rate':3
}
 
rounds_lock = threading.Lock()
gun_can_fire = threading.Event()
 
def runprop():
    while True:
        with rounds_lock:
            if gun['rounds'] <= 0:
                break
        
        gun_can_fire.clear()
        
        print 'Prop in gun zone'
        time.sleep(prop['rpm']/4); #time in zone
        print 'prop out of gun zone'
 
        gun_can_fire.set()
 
        time.sleep(prop['rpm']/2); #time to spin back to zone
 
    print 'prop done'
 
def rungun():
    while True:
        gun_can_fire.wait()
        with rounds_lock:
            gun['rounds'] -= 1
            if gun['rounds'] % gun['tracer_rate'] == 0:
                print 'tracer fired'
            if gun['rounds'] <= 0:
                break
            print 'rounds %d' % gun['rounds']
        time.sleep(gun['rate'])
    print 'gun done'
 
if __name__ == '__main__':
    prop_thread = threading.Thread(target=runprop)
    gun_thread = threading.Thread(target=rungun)
 
    gun_can_fire.clear()
 
    prop_thread.start()
    gun_thread.start()
 
    prop_thread.join()
    gun_thread.join()