Best Python code snippet using autotest_python
command.py
Source: command.py
...28class AbortException(Exception):29 """Indicates early abort on SIGINT, SIGTERM or internal hard timeout."""30 pass31@contextmanager32def handle_sigterm(process, abort_fun, enabled):33 """Call`abort_fun` on sigterm and restore previous handler to prevent34 erroneous termination of an already terminated process.35 Args:36 process: The process to terminate.37 abort_fun: Function taking two parameters: the process to terminate and38 an array with a boolean for storing if an abort occured.39 enabled: If False, this wrapper will be a no-op.40 """41 # Variable to communicate with the signal handler.42 abort_occured = [False]43 def handler(signum, frame):44 abort_fun(process, abort_occured)45 if enabled:46 previous = signal.signal(signal.SIGTERM, handler)47 try:48 yield49 finally:50 if enabled:51 signal.signal(signal.SIGTERM, previous)52 if abort_occured[0]:53 raise AbortException()54class BaseCommand(object):55 def __init__(self, shell, args=None, cmd_prefix=None, timeout=60, env=None,56 verbose=False, resources_func=None, handle_sigterm=False):57 """Initialize the command.58 Args:59 shell: The name of the executable (e.g. d8).60 args: List of args to pass to the executable.61 cmd_prefix: Prefix of command (e.g. a wrapper script).62 timeout: Timeout in seconds.63 env: Environment dict for execution.64 verbose: Print additional output.65 resources_func: Callable, returning all test files needed by this command.66 handle_sigterm: Flag indicating if SIGTERM will be used to terminate the67 underlying process. Should not be used from the main thread, e.g. when68 using a command to list tests.69 """70 assert(timeout > 0)71 self.shell = shell72 self.args = args or []73 self.cmd_prefix = cmd_prefix or []74 self.timeout = timeout75 self.env = env or {}76 self.verbose = verbose77 self.handle_sigterm = handle_sigterm78 def execute(self):79 if self.verbose:80 print('# %s' % self)81 process = self._start_process()82 with handle_sigterm(process, self._abort, self.handle_sigterm):83 # Variable to communicate with the timer.84 timeout_occured = [False]85 timer = threading.Timer(86 self.timeout, self._abort, [process, timeout_occured])87 timer.start()88 start_time = time.time()89 stdout, stderr = process.communicate()90 duration = time.time() - start_time91 timer.cancel()92 return output.Output(93 process.returncode,94 timeout_occured[0],95 stdout.decode('utf-8', 'replace').encode('utf-8'),96 stderr.decode('utf-8', 'replace').encode('utf-8'),...
main.py
Source: main.py
...4from signal import signal, SIGTERM, SIGINT5def main():6 listener = RabbitListener(SkService())7 listener.run()8 def handle_sigterm(*_):9 print("Shutdown signal received")10 listener.close()11 print("Shutdown gracefully")12 signal(SIGTERM, handle_sigterm)13 signal(SIGINT, handle_sigterm)14 try:15 listener.close()16 except KeyboardInterrupt:17 handle_sigterm()18if __name__ == '__main__':19 DI()...
sigterm.py
Source: sigterm.py
...5 Used to exit quickly from docker containers6 https://lemanchet.fr/articles/gracefully-stop-python-docker-container.html7 """8 import signal9 def handle_sigterm(*args):10 raise KeyboardInterrupt()
...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!