Best Python code snippet using localstack_python
publisher.py
Source:publisher.py
...56 self._stopping = threading.Event()57 self._stopped = threading.Event()58 def handle(self, event: Event):59 self._queue.put_nowait(event)60 self.checked_flush()61 def close(self):62 if self._stopping.is_set():63 return64 self._stopping.set()65 self._command_queue.put(self._cmd_stop)66 def close_sync(self, timeout: Optional[float] = None):67 self.close()68 return self._stopped.wait(timeout)69 def flush(self):70 self._command_queue.put(self._cmd_flush)71 self._last_flush = time.time()72 def checked_flush(self):73 """74 Runs flush only if a flush condition is met.75 """76 if config.DEBUG_ANALYTICS:77 LOG.debug(78 "analytics queue size: %d, command queue size: %d, time since last flush: %.1fs",79 self._queue.qsize(),80 self._command_queue.qsize(),81 time.time() - self._last_flush,82 )83 if self._queue.qsize() >= self.flush_size:84 self.flush()85 return86 if time.time() - self._last_flush >= self.flush_interval:87 self.flush()88 return89 def _run_flush_schedule(self, *_):90 while True:91 if self._stopping.wait(self.flush_interval):92 return93 self.checked_flush()94 def run(self, *_):95 flush_scheduler = start_thread(self._run_flush_schedule)96 try:97 while True:98 command = self._command_queue.get()99 if command is self._cmd_flush or command is self._cmd_stop:100 try:101 self._do_flush()102 except Exception:103 if config.DEBUG_ANALYTICS:104 LOG.exception("error while flushing events")105 if command is self._cmd_stop:106 return107 finally:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!