Deutsch English Français Italiano |
<mailman.1.1732710433.2965.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: marc nicole <mk1853387@gmail.com> Newsgroups: comp.lang.python Subject: How to break while loop based on events raised in a thread (Python 2.7) Date: Wed, 27 Nov 2024 13:28:06 +0100 Lines: 55 Message-ID: <mailman.1.1732710433.2965.python-list@python.org> References: <CAGJtH9SuFdPOF80BW2x+obM7-CbaqRuHOnraSmxmD+-yLqOOPw@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: news.uni-berlin.de hAZHCmMrFs2cH8RBzgGrYwCSrLNFiCaA/SYSvBbHz/7g== Cancel-Lock: sha1:H0E9iJBsZJZiEXW4DJCYdTOSdGE= sha256:Uk01oUg3sfgalJB7CurNLbYxKmIWR0TVU0Zc4E4j08A= Return-Path: <mk1853387@gmail.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=UiWU0HXv; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'loop': 0.07; 'breaks': 0.09; 'elif': 0.09; 'else:': 0.09; 'subject:Python': 0.12; '>': 0.14; 'accordingly': 0.16; 'condition.': 0.16; 'instance': 0.16; 'outer': 0.16; 'secs': 0.16; 'skip:s 230': 0.16; 'subject:2.7': 0.16; 'subject:loop': 0.16; 'subject:thread': 0.16; 'subject:while': 0.16; 'problem': 0.16; 'to:addr:python-list': 0.20; 'instructions': 0.22; 'to:no real name:2**1': 0.22; 'code': 0.23; 'cannot': 0.25; 'perform': 0.26; 'sfxlen:2': 0.31; 'subject:How': 0.31; 'takes': 0.31; 'message-id:@mail.gmail.com': 0.31; 'program': 0.32; 'checks': 0.32; 'execution': 0.32; 'performed': 0.32; 'but': 0.32; 'there': 0.33; 'received:google.com': 0.34; 'requires': 0.34; 'from:addr:gmail.com': 0.34; 'following': 0.35; 'using': 0.37; 'class': 0.37; 'break': 0.39; 'skip:u 20': 0.39; 'seconds': 0.40; 'want': 0.40; 'event': 0.40; 'method': 0.61; 'true': 0.63; 'skip:b 10': 0.63; 'pass': 0.64; 'upon': 0.65; 'skip:t 20': 0.65; '8bit%:21': 0.68; 'further': 0.69; 'below': 0.69; 'raised': 0.70; '<span': 0.76; '2-3': 0.84; 'subject:based': 0.84; 'instant': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732710430; x=1733315230; darn=python.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=dFzoplmYisymksn1w+ELUXiotLX42gOpUVZ7tJCmAZk=; b=UiWU0HXvGNyfmhQWJnqnFasVDnpaSoppZEBSfs9GyONo/rVNrfQci9MwdinZ9gVb9U DgIF+1bVfLcA34ujqctePYoFJM/T8KTCmWuF6rsKeFOzbWNSYLu/HrJXAUxEz5ywgDIi NAPej13LWENOyhUNjGv5Qi0hnQ9DwdDhZ62bn+5c6b3PjTzAGWBzALaLhT5MD7LpFNOA OrUE7Z6gn04WAqKpWW1UOcq0V3fdJ8e7sxAdiy1Akk3GQQGNCpHGH/Vbn5YZGSAaIIPm bEAc317TgJD1XZnJc9da2e1BFUwDo5Gg/dJU4beaHW4n3POdntJ9BbXeSGr9FdHFzN4u 8TiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732710430; x=1733315230; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dFzoplmYisymksn1w+ELUXiotLX42gOpUVZ7tJCmAZk=; b=TdPQNQYPgsi7uRwejjqTSR45Sgg2x6Cs+uPbwy2g0CNhiyupgQSAyhykc3L9qLiGVp kBTbVrEQlamRYVLwc91MctkoqjQaYP54N3Ntwc9qqpsffXrZNcjkmIk5UIAtcLVz6y0r PKdpe8ia9yhQ7YUiu7eDfPM3oLz+V0wepmhNFpI67c6wbqur8BQDOVFaMYbbWcK/jCTg TlCUthV4JzWIrflDuqbpLndpfq7+2I30YA0IVAeW4GAYYPM3vlqTNnBOZ9e88iJri1ZQ e3oig7RmzPwbAS+D6NZgpCIG1Kvd7ns2wQ01G4tj9ie/lMW08FsX9R0KoVgM0ivOmFY/ wMGQ== X-Forwarded-Encrypted: i=1; AJvYcCVZb9RHRWXsBmo1ZZTLpREDECEbyjh2hFi0i0qi3fX4trJfCuvBb6OYTG7E7MAfk+onvXJA3W6w0/otCw==@python.org X-Gm-Message-State: AOJu0YzLDHkmKPtxuQzVn6iVlAs2iUD0Fi0nMv8S5Kx10w6HULGn3eDb hoLx7CUDkHXziTNBkeuYUy45Ohh8lL8UTdMUfRgC7LWygtJUNZrNotcO4i+QlyQoHOD7Diqu2At v7GsEml2Yj3j32KioTnzlRo0dWDY40lfW X-Gm-Gg: ASbGnct4UHfphzSbbksROg5Zt4Xqo2AvkHOtiOwPn+f9eK5JXcXYwW47vJ3WUuGGqWQ c1erhvUTYD0kI1KnqwvGyi2D+tdKX/0Rp X-Google-Smtp-Source: AGHT+IETGX6cHk8swYmiJzpxOcMhzTi/bp2suAA0k9z3qo9BI/FqPD9s/sXPUTYeZfflSDiI3J44yIUYk8kMXW6dl8U= X-Received: by 2002:a05:690c:6113:b0:6e5:aaf7:68d0 with SMTP id 00721157ae682-6ef3721490fmr30485517b3.18.1732710428628; Wed, 27 Nov 2024 04:27:08 -0800 (PST) X-Content-Filtered-By: Mailman/MimeDel 2.1.39 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> List-Archive: <https://mail.python.org/pipermail/python-list/> List-Post: <mailto:python-list@python.org> List-Help: <mailto:python-list-request@python.org?subject=help> List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> X-Mailman-Original-Message-ID: <CAGJtH9SuFdPOF80BW2x+obM7-CbaqRuHOnraSmxmD+-yLqOOPw@mail.gmail.com> Bytes: 7561 I am using the below class1 code to detect some event through the method check_for_the_event() # Some class1def check_for_the_event(self): thread1 = threading.Timer(2, self.check_for_the_event) thread1.start()# some processingif event is detected: self.event_ok = Trueelse: self.event_ok = False then I pass an instance of that class to the below class to know when the event is on or off and act upon its value accordingly using the following below code: # execution of other part of the program (where self.another_class_instance.event_ok = False and self.some_other_condition is true) current_time = current_time_some_cond = current_max_time = time.time() while not self.another_class_instance.event_ok and self.some_other_condition: while self.some_other_condition and not self.another_class_instance.event_ok:#self.some_other_condition takes up to 10 secs to be checked (minimum 5 secs) if time.time() > current_time + 5: current_time = time.time() # some processing else: while not self.another_class_instance.event_ok: #processing if time.time() > current_max_time + 60 * 2 and not self.another_class_instance.event_ok: #some other processing if time.time() > current_time_some_cond + 10 and not self.cond1 and not self.another_class_instance.event_ok: # some processing that takes 2-3 seconds self.cond1 = True current_time_some_cond = time.time() elif self.cond1 and time.time() > current_time_some_cond + 10 and not self.another_class_instance.event_ok: current_time_some_cond = time.time() #some other processing that takes 2-3 seconds else: pass else: pass The problem is the real time execution of the program (in class2) requires an instant check to be performed and that cannot wait until the current loop instructions finish, and I want is to break out of the outer while loop if the event is on without further checking any other condition. for now I perform multiple checks at each if or while statement, but is there a IO async based method that breaks out of the loop when the event is raised in the thread?