def run(self):
while True:
self.conn = self.conn_queue.get()
print(\'worker is running : \' + self.getName() +\' has work with \' + format(self.conn) )
try:
if self.conn.poll(1):
self.status_taskdone=False
self.buffer=self.conn.recv_bytes()
#until task have done but only 5 times it will repaet
for a in range(5):
#while not self.status_taskdone:
#lock data list
self.locker.acquire()
#find data in cache
#cache : [url, time of using, time, data]
for element in self.cache_list:
if element[0] == self.buffer:
#check whether the cache 60s old
if time.time - element[2] < 60:
try:
self.conn.send_bytes( bytes(element[1].encode(\'utf8\')) )
break;
except:
print(\"client doesn\'t take data\")
self.status_taskdone=True
else:
pass
#release lock anyway
self.locker.release()
#couldn\'t not find in cache. ask 1to build cache data
if not self.status_taskdone:
self.miner_queue.put(self.buffer)
time.sleep(1)
#take 2 second rest for miner to take data to cache list
#if failed to fetch cache
if not self.status_taskdone:
try:
self.conn.send_bytes(b\'Failed to create cache\')
except:
print(\'Lose connection\')
#if the client doesn\'t have a query within 2 second
else:
print(\'Lose connection\')
except:
print(\"Break while poll\")
finally:
#job done
self.conn.close()
self.conn_queue.task_done()
너무 많은가?
while True:
self.conn = self.conn_queue.get()
print(\'worker is running : \' + self.getName() +\' has work with \' + format(self.conn) )
try:
if self.conn.poll(1):
self.status_taskdone=False
self.buffer=self.conn.recv_bytes()
#until task have done but only 5 times it will repaet
for a in range(5):
#while not self.status_taskdone:
#lock data list
self.locker.acquire()
#find data in cache
#cache : [url, time of using, time, data]
for element in self.cache_list:
if element[0] == self.buffer:
#check whether the cache 60s old
if time.time - element[2] < 60:
try:
self.conn.send_bytes( bytes(element[1].encode(\'utf8\')) )
break;
except:
print(\"client doesn\'t take data\")
self.status_taskdone=True
else:
pass
#release lock anyway
self.locker.release()
#couldn\'t not find in cache. ask 1to build cache data
if not self.status_taskdone:
self.miner_queue.put(self.buffer)
time.sleep(1)
#take 2 second rest for miner to take data to cache list
#if failed to fetch cache
if not self.status_taskdone:
try:
self.conn.send_bytes(b\'Failed to create cache\')
except:
print(\'Lose connection\')
#if the client doesn\'t have a query within 2 second
else:
print(\'Lose connection\')
except:
print(\"Break while poll\")
finally:
#job done
self.conn.close()
self.conn_queue.task_done()
너무 많은가?
횽 파이썬 하실때 뭘로 작성하심?? 저는 vim으로 짜는데 주석 달면 블록 ,인덴테이션 쌩까고 맨앞으로 보내버림 ㅠ
파워한 이클립스--