-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup.py
executable file
·63 lines (52 loc) · 1.59 KB
/
startup.py
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
#!/usr/bin/env python
# vim: set ts=8 sw=8 sts=8 list nu:
# Main includes
import sys
import time
from threading import *
# Thread message queueing and priortising
import Queue
from system.queue import Queue as Q
from system.threads import threads
from system.connections import sysConnects
# Setup threads, connections, conditions, queues, locks, and semophores
s_conds = {}
s_locks = {}
s_sema = {}
s_queues = Q()
s_connects = sysConnects(s_queues, s_conds, s_locks, s_sema)
s_threads = threads(s_queues, s_connects, s_conds, s_locks, s_sema)
# Create our main control queue
s_queues.create('control')
# Close all threads and exit
def quit_sys():
# Close all our threads
for i in s_threads.t_dict:
s_queues.put(i,'close',{})
# Force the console to close
s_threads.t_dict['console']['thread'].close()
raise SystemExit
# Parse information sent into the queue
def parse_queue(block=False, timeout=1):
while True:
try:
# We "pop" an item off the start of the queue by calling
# the get method. Once we have the item in a list, we grab
# the function name and arguments to call. The arguments
# are placed into the method using a variadic call by
# prepending the ** to the beginning of the argument.
runner = s_queues.get('control', block=False, timeout=1)
globals()[runner[1]](**runner[2])
except Queue.Empty:
# Nothing left to do, time to die
return
# Start our console system
s_locks['con'] = Lock()
s_threads.create('interface.console.console')
main = current_thread()
main.name = "main"
while 1:
time.sleep(0.025)
parse_queue()
s_connects.parse_queue()
s_threads.parse_queue()