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
|
import ConfigParser
import atexit
import os
import time
import subprocess
# Multiple modems can be supported by reading from the .cfg file
config = ConfigParser.RawConfigParser()
config.read('modems.cfg')
# Get the number of modems and fire one thread for each modem
modems = config.getint('Main', 'Modems')
sahanapydatabase = config.get('Main', 'Database')
debug = config.getint('Main', 'Debug')
posturl = config.get('Main', 'PostURL')
branch = config.get('Main', 'Branch')
if debug:
print sahanapydatabase
work = []
def killsubprocess():
"""Kills all the spawned subprocess"""
global modems
print "Quitting"
for i in range(modems):
work[i].kill()
atexit.register(killsubprocess)
for i in range(modems):
Modem = "Modem" + str(i+1)
port = config.get(Modem, 'Port')
baudrate = config.get(Modem, 'BaudRate')
work.append(subprocess.Popen(("python", "SerialWorker.py", port, baudrate,
str(debug),posturl,sahanapydatabase,branch)))
# After everything is done we sit back and wait for the some one to shut us
# down :D
try:
while 1:
pass
except KeyboardInterrupt:
pass
|