diff options
| author | Daniel P. Berrange <berrange@redhat.com> | 2017-04-04 14:45:05 +0100 |
|---|---|---|
| committer | Daniel P. Berrange <berrange@redhat.com> | 2017-04-04 15:28:50 +0100 |
| commit | 6c8d625676e3305e689be3c210f3fa8d38dc266e (patch) | |
| tree | 9cb46066ce1add5a6c27e3905f775ebf6d9818b6 /examples | |
| parent | 1770fa45b455d1eee3289d9b941a9939b27b5b7e (diff) | |
| download | libvirt-python-6c8d625676e3305e689be3c210f3fa8d38dc266e.tar.gz | |
event-test: add timeout to exit event loop
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/event-test.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/examples/event-test.py b/examples/event-test.py index 851c09b..751a140 100755 --- a/examples/event-test.py +++ b/examples/event-test.py @@ -651,15 +651,17 @@ def usage(): print(" --help, -h Print(this help message") print(" --debug, -d Print(debug output") print(" --loop, -l Toggle event-loop-implementation") + print(" --timeout=SECS Quit after SECS seconds running") def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "hdl", ["help", "debug", "loop"]) + opts, args = getopt.getopt(sys.argv[1:], "hdl", ["help", "debug", "loop", "timeout="]) except getopt.GetoptError as err: # print help information and exit: print(str(err)) # will print something like "option -a not recognized" usage() sys.exit(2) + timeout = None for o, a in opts: if o in ("-h", "--help"): usage() @@ -670,6 +672,8 @@ def main(): if o in ("-l", "--loop"): global use_pure_python_event_loop use_pure_python_event_loop ^= True + if o in ("--timeout"): + timeout = int(a) if len(args) >= 1: uri = args[0] @@ -741,7 +745,9 @@ def main(): # of demo we'll just go to sleep. The other option is to # run the event loop in your main thread if your app is # totally event based. - while run: + count = 0 + while run and (timeout is None or count < timeout): + count = count + 1 time.sleep(1) |
