PDA

View Full Version : QNetworkReply doesn't abort/close - PyQT



dan252
3rd May 2013, 15:51
My Code: (relevent parts)


def update(self):
request = QNetworkRequest()
request.setUrl(QUrl("someurl"))
self.network_manager.finished.connect(self._update )
self.network_manager.get(request)

def _update(self, reply): # update stage 2
if not reply.error() == QNetworkReply.NoError:
# request probably failed
print(reply.error())
print(reply.errorString())
print("retrying")
self.update()
else:
reply.abort()
#print(str(reply.readAll().data()))
data = json.loads(str(reply.readAll().data())) # get data
#work with the data (irrelevant)

def sendBearer_req(self):

request = QNetworkRequest()
request.setUrl(QUrl("someotherurl"))

self.network_manager = QNetworkAccessManager()
self.network_manager.finished.connect(self._reques t_finished)

self.network_manager.post(request, self.urlencode_post({'some' : 'thing'}))

def sendBearer(self, reply):
reply.abort()
ans = reply.readAll()
print(ans)
time.sleep(5)
print(ans)

try:
self.bearer = json.loads(str(ans))
self.update()
except:
raise #for debugging
self.sendBearer_req() #retry

def _request_finished(self, reply):
if not reply.error() == QNetworkReply.NoError:
# request probably failed
print(reply.error())
print(reply.errorString())
print("retrying")
self.sendBearer_req()
else:
self.sendBearer(reply)

Problem:

in this part:


reply.abort()
ans = reply.readAll()
print(ans)
time.sleep(5)
print(ans)

I'm pretty sure the `abort` isn't working because on the first `print` it prints just what i want but then, while it waits, apparently it continues with the code and enters the `update` function where it sends another request. Therefor in the second `print` the two replies mix together and it prints the both.

(btw I tried `close` as well - same result)

What am I doing wrong?

wysota
7th May 2013, 01:41
What is the expected behaviour? Why are you calling time.sleep(5)?