Donate CPU: Speedup server. Keep packageIndex in package-index.txt

This commit is contained in:
Daniel Marjamäki 2018-08-25 20:58:31 +02:00
parent 829a373416
commit c65d79c0ec
1 changed files with 15 additions and 5 deletions

View File

@ -100,7 +100,7 @@ class HttpClientThread(Thread):
package = package[:package.find(' ')]
filename = os.path.expanduser('~/donated-results/') + package
if not os.path.isfile(filename):
print('HTTP/1.1 404 Not Found\n\n')
print('HTTP/1.1 404 Not Found')
connection.send('HTTP/1.1 404 Not Found\n\n')
else:
f = open(filename,'rt')
@ -110,6 +110,7 @@ class HttpClientThread(Thread):
print('HttpClientThread: sleep 30 seconds..')
time.sleep(30)
print('HttpClientThread: stopping')
time.sleep(1)
self.connection.close()
except:
return
@ -127,7 +128,13 @@ if __name__ == "__main__":
print('fatal: there are no packages')
sys.exit(1)
packageIndex = int(time.time()) % len(packages)
packageIndex = 0
if os.path.isfile('package-index.txt'):
f = open('package-index.txt', 'rt')
packageIndex = int(f.read())
if packageIndex < 0 or packageIndex >= len(packages):
packageIndex = 0
f.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ -162,6 +169,9 @@ if __name__ == "__main__":
packageIndex += 1
if packageIndex >= len(packages):
packageIndex = 0
f = open('package-index.txt', 'wt')
f.write(str(packageIndex) + '\n')
f.close()
connection.close()
elif cmd.startswith('write\nftp://'):
# read data