Python: How to end while True loop -


how go ending while true loop, want loop end @ marked location, tried both break , continue, both don't end loop. keeps script running , pretty stays there, doing nothing.

class myhandler(basehttprequesthandler): def log_message(self, format, *args):     return def do_get(self):     if self.path.startswith("/checktransfer"):         qs = {}         path = self.path         if '?' in self.path:             qs = parse_qs(urlparse(self.path).query)             print "received transfer check request transfer id: " + qs["transferid"][0]             while true:                 if checkprogress(qs["transferid"][0]) == 1:                     self.send_response(200)                     self.send_header('content-type', 'text/json')                     self.end_headers()                     self.wfile.write('{"status" : 1}')                     print "transfer completed! checking downloads"                     ******* break; *******                 ******* ^ need end loop *******                 elif checkprogress(qs["transferid"][0]) == 0:                     self.send_response(200)                     self.send_header('content-type', 'text/json')                     self.end_headers()                     self.wfile.write('{"status" : 0}')                     print "incomplete transfer, waiting..."                     time.sleep(3)                 elif checkprogress(qs["transferid"][0]) == 2:                     self.send_response(200)                     self.send_header('content-type', 'text/json')                     self.end_headers()                     print "could not find transfer, removed"                     self.wfile.write('{"status" : 2}')                     break; 

your if statements expect values 0, 1 or 2. if 100% sure possible values, should catch unexpected cases , raise exception if happens - regardless of whether or not cause of never-ending script in particular case, potential loophole in code:

while true:     if         ....     else:         raise exception("unexpected value: " + checkprogress(qs["transferid"][0])) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -