-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2armchair.py
81 lines (63 loc) · 2.12 KB
/
i2armchair.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
from time import sleep
import argparse
import socket
import sys
import thread
import threading
def processSentance(sentance,sleepLength):
print "Sentance is : ", sentance
sleep(sleepLength/100.0)
class FileThread (threading.Thread):
"""This just reads the file."""
def __init__( self,theLogFile ,theSleepLength ):
threading.Thread.__init__(self)
global infile
self.infile = theLogFile
self.sleepLength = theSleepLength
self.mySockets = []
self.leaving = False
#print "init"
def run ( self ):
global infile
global sleepLength
global mySockets
sentance = ""
#print(len(self.mySockets))
for line in self.infile:
if ((line == "") or (self.leaving)):
print "leaving now"
break
line = line[0:1]
sentance += line
if line == "\n":
if len(sentance) > 4:
processSentance(sentance,self.sleepLength)
for data in sentance:
for theSocket in self.mySockets:
try:
theSocket.send(data)
except socket.error, msg:
theSocket.close()
self.mySockets.remove(theSocket)
theSocket = None
break
continue
sentance = ""
def addSocket(self, socket):
self.mySockets.append(socket)
#print(len(self.mySockets))
def delSocket(self, socket):
mySockets.remove(socket)
def exit(self):
for theSocket in self.mySockets:
try:
theSocket.close()
except socket.error, msg:
self.mySockets.remove(theSocket)
theSocket = None
break
continue
print "All closed lets exit"
global leaving
self.leaving = True