diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py index 498060a2e..d313f2adc 100755 --- a/tools/donate-cpu.py +++ b/tools/donate-cpu.py @@ -160,10 +160,6 @@ while True: package = package_url else: package = get_package(server_address) - while len(package) == 0: - print("network or server might be temporarily down.. will try again in 30 seconds..") - time.sleep(30) - package = get_package(server_address) tgz = download_package(work_path, package, bandwidth_limit) if tgz is None: print("No package downloaded") diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index f04b0f094..39e544767 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -135,20 +135,21 @@ def get_packages_count(server_address): def get_package(server_address, package_index=None): - print('Connecting to server to get assigned work..') package = b'' - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - try: - sock.connect(server_address) - if package_index is None: - sock.send(b'get\n') - else: - request = 'getPackageIdx:' + str(package_index) + '\n' - sock.send(request.encode()) - package = sock.recv(256) - except socket.error: - pass - sock.close() + while not package: + print('Connecting to server to get assigned work..') + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.connect(server_address) + if package_index is None: + sock.send(b'get\n') + else: + request = 'getPackageIdx:' + str(package_index) + '\n' + sock.send(request.encode()) + package = sock.recv(256) + except socket.error: + print("network or server might be temporarily down.. will try again in 30 seconds..") + time.sleep(30) return package.decode('utf-8') diff --git a/tools/test-my-pr.py b/tools/test-my-pr.py index 98f4cd9d0..f6b17823a 100755 --- a/tools/test-my-pr.py +++ b/tools/test-my-pr.py @@ -9,7 +9,6 @@ import argparse import os import sys import random -import time import subprocess if __name__ == "__main__": @@ -73,9 +72,6 @@ if __name__ == "__main__": while packages_processed < args.p and len(packages_idxs) > 0: package = lib.get_package(lib.server_address, packages_idxs.pop()) - if len(package) == 0: - print("network or server might be temporarily down..") - sys.exit(1) tgz = lib.download_package(work_path, package, None) if tgz is None: