Donate CPU: Speedup server. Keep packageIndex in package-index.txt
This commit is contained in:
parent
829a373416
commit
c65d79c0ec
|
@ -100,7 +100,7 @@ class HttpClientThread(Thread):
|
||||||
package = package[:package.find(' ')]
|
package = package[:package.find(' ')]
|
||||||
filename = os.path.expanduser('~/donated-results/') + package
|
filename = os.path.expanduser('~/donated-results/') + package
|
||||||
if not os.path.isfile(filename):
|
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')
|
connection.send('HTTP/1.1 404 Not Found\n\n')
|
||||||
else:
|
else:
|
||||||
f = open(filename,'rt')
|
f = open(filename,'rt')
|
||||||
|
@ -110,6 +110,7 @@ class HttpClientThread(Thread):
|
||||||
print('HttpClientThread: sleep 30 seconds..')
|
print('HttpClientThread: sleep 30 seconds..')
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
print('HttpClientThread: stopping')
|
print('HttpClientThread: stopping')
|
||||||
|
time.sleep(1)
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
@ -127,7 +128,13 @@ if __name__ == "__main__":
|
||||||
print('fatal: there are no packages')
|
print('fatal: there are no packages')
|
||||||
sys.exit(1)
|
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 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
@ -162,6 +169,9 @@ if __name__ == "__main__":
|
||||||
packageIndex += 1
|
packageIndex += 1
|
||||||
if packageIndex >= len(packages):
|
if packageIndex >= len(packages):
|
||||||
packageIndex = 0
|
packageIndex = 0
|
||||||
|
f = open('package-index.txt', 'wt')
|
||||||
|
f.write(str(packageIndex) + '\n')
|
||||||
|
f.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
elif cmd.startswith('write\nftp://'):
|
elif cmd.startswith('write\nftp://'):
|
||||||
# read data
|
# read data
|
||||||
|
|
Loading…
Reference in New Issue