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
This commit is contained in:
Rikard Falkeborn 2019-12-12 15:04:25 +01:00 committed by Daniel Marjamäki
parent 370196a14c
commit 3ff4d83e6d
1 changed files with 2 additions and 2 deletions

View File

@ -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')