-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessthread.py
55 lines (49 loc) · 1.2 KB
/
processthread.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
"""
This thread processes the client/server interaction
It is called from threadspawner.py
Usage: create by passing in a valid socket and then call .start()
"""
import bid
import time
from threading import Thread
class processthread(Thread):
def __init__(self, socket, dataset):
Thread.__init__(self)
self.socket = socket
self.dataset = dataset
def run(self):
#print "process thread started========="
msocket = self.socket
msocket.settimeout(0.1)
total_data=[]
data=''
begin=time.time()
while True:
if total_data and time.time() - begin > 0.005:
break
elif time.time() - begin > 0.01:
break
try:
data=msocket.recv(96)
if data:
total_data.append(data)
begin=time.time()
else:
time.sleep(1)
except:
pass
readin = ''.join(total_data)
#print repr(readin)
test = time.time()
ourbid = bid.Bid(readin, test, self.dataset) #changed
#print str(test)
#check valid socket
try:
status = msocket.sendall(ourbid.reply)
except:
msocket.close()
return
if status is None:
#that is if sendAll worked
ourbid.store()
msocket.close()