6 examples of 'python main loop' in Python

Every line of 'python main loop' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
141def run_main_loop():
142 """
143 Runs the main loop. Note, this is not guaranteed to return on all platforms.
144 You should never call this in unit tests --- if you have a test that requires
145 UI or that wants to do asynchronous tests, derive from UITestcase which will
146 call this for you.
147 """
148 _initialize_if_needed()
149 _platform_message_loop.run_main_loop()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

363def main_loop(self):
364 self.console_reader.start()
365 self.serial_reader.start()
366 try:
367 while self.console_reader.alive and self.serial_reader.alive:
368 (event_tag, data) = self.event_queue.get()
369 if event_tag == TAG_KEY:
370 self.handle_key(data)
371 elif event_tag == TAG_SERIAL:
372 self.handle_serial_input(data)
373 if self._invoke_processing_last_line_timer is not None:
374 self._invoke_processing_last_line_timer.cancel()
375 self._invoke_processing_last_line_timer = threading.Timer(0.1, self.invoke_processing_last_line)
376 self._invoke_processing_last_line_timer.start()
377 # If no futher data is received in the next short period
378 # of time then the _invoke_processing_last_line_timer
379 # generates an event which will result in the finishing of
380 # the last line. This is fix for handling lines sent
381 # without EOL.
382 elif event_tag == TAG_SERIAL_FLUSH:
383 self.handle_serial_input(data, finalize_line=True)
384 else:
385 raise RuntimeError("Bad event data %r" % ((event_tag,data),))
386 except SerialStopException:
387 sys.stderr.write(ANSI_NORMAL + "Stopping condition has been received\n")
388 finally:
389 try:
390 self.console_reader.stop()
391 self.serial_reader.stop()
392 # Cancelling _invoke_processing_last_line_timer is not
393 # important here because receiving empty data doesn't matter.
394 self._invoke_processing_last_line_timer = None
395 except Exception:
396 pass
397 sys.stderr.write(ANSI_NORMAL + "\n")
32def mainLoop():
33 reading = lightSensor.lightLevel()
34 message = "Light level: " + str(reading)
35 psm.screen.termPrintAt(0, message)
63def main_loop():
64 bot.polling(True)
65 while 1:
66 time.sleep(3)
867async def main(loop):
868 logging.basicConfig(level=logging.DEBUG)
869 parser = argparse.ArgumentParser(description="Commands: mode fan temp")
870 parser.add_argument(
871 "--user",
872 type=str,
873 dest="user",
874 help="username for user.intesishome.com",
875 metavar="USER",
876 default=None,
877 )
878 parser.add_argument(
879 "--password",
880 type=str,
881 dest="password",
882 help="password for user.intesishome.com",
883 metavar="PASSWORD",
884 default=None,
885 )
886 parser.add_argument(
887 "--device",
888 type=str,
889 dest="device",
890 help="IntesisHome or airconwithme",
891 metavar="IntesisHome or airconwithme",
892 default=DEVICE_INTESISHOME,
893 )
894 args = parser.parse_args()
895
896 if (not args.user) or (not args.password):
897 help()
898 sys.exit(0)
899
900 controller = IntesisHome(
901 args.user, args.password, loop=loop, device_type=args.device
902 )
903 await controller.connect()
904 print(repr(controller.get_devices()))
905 await controller.stop()
33def run():
34 print_out("\nStarting interactive session.\n\n")
35
36 vars = globals().copy()
37 vars.update(locals())
38 shell = code.InteractiveConsole(vars)
39 shell.interact()

Related snippets