From 3ff4d83e6d4f0924df25b163d715b7aaa0ed42a7 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Thu, 12 Dec 2019 15:04:25 +0100 Subject: [PATCH] donate_cpu_lib: Fix python 3 crash if fail to get package (#2445) * donate_cpu_lib: Fix python 3 crash if fail to get package Decoding a string is not allowed in python 3 (in python 2 it works). If fetching the package fails, assign an empty byte string instead to avoid crashing. * Initialize package instead --- tools/donate_cpu_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 14fac5b75..3c6429112 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -129,7 +129,7 @@ def get_packages_count(server_address): def get_package(server_address, package_index = None): print('Connecting to server to get assigned work..') - package = None + package = b'' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(server_address) @@ -140,7 +140,7 @@ def get_package(server_address, package_index = None): sock.send(request.encode()) package = sock.recv(256) except socket.error: - package = '' + pass sock.close() return package.decode('utf-8')