Skip to content

Commit 3ff4d83

Browse files
rikardfalkeborndanmar
authored andcommitted
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
1 parent 370196a commit 3ff4d83

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tools/donate_cpu_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def get_packages_count(server_address):
129129

130130
def get_package(server_address, package_index = None):
131131
print('Connecting to server to get assigned work..')
132-
package = None
132+
package = b''
133133
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
134134
try:
135135
sock.connect(server_address)
@@ -140,7 +140,7 @@ def get_package(server_address, package_index = None):
140140
sock.send(request.encode())
141141
package = sock.recv(256)
142142
except socket.error:
143-
package = ''
143+
pass
144144
sock.close()
145145
return package.decode('utf-8')
146146

0 commit comments

Comments
 (0)