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:
parent
370196a14c
commit
3ff4d83e6d
|
@ -129,7 +129,7 @@ def get_packages_count(server_address):
|
||||||
|
|
||||||
def get_package(server_address, package_index = None):
|
def get_package(server_address, package_index = None):
|
||||||
print('Connecting to server to get assigned work..')
|
print('Connecting to server to get assigned work..')
|
||||||
package = None
|
package = b''
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
try:
|
try:
|
||||||
sock.connect(server_address)
|
sock.connect(server_address)
|
||||||
|
@ -140,7 +140,7 @@ def get_package(server_address, package_index = None):
|
||||||
sock.send(request.encode())
|
sock.send(request.encode())
|
||||||
package = sock.recv(256)
|
package = sock.recv(256)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
package = ''
|
pass
|
||||||
sock.close()
|
sock.close()
|
||||||
return package.decode('utf-8')
|
return package.decode('utf-8')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue