diff options
author | Ryan Harper <ryan.harper@canonical.com> | 2018-08-31 21:47:18 +0000 |
---|---|---|
committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2018-08-31 21:47:18 +0000 |
commit | 43e51a04515686a15c410d1a16dd5ff06fd1afd4 (patch) | |
tree | 4ad8fb33fc749669f7a1ef583cfe82979b207bb2 /cloudinit/cmd/main.py | |
parent | 9c35f9762028b8bf15cdcd6b42c0fafc233ddda3 (diff) | |
download | vyos-cloud-init-43e51a04515686a15c410d1a16dd5ff06fd1afd4.tar.gz vyos-cloud-init-43e51a04515686a15c410d1a16dd5ff06fd1afd4.zip |
hyperv_reporting_handler: simplify threaded publisher
Switch the implementation to a daemon thread which uses a
blocking get from the Queue. No additional locking or flag checking
is needed since the Queue itself handles acquiring the lock as needed.
cloud-init only has a single producer (the main thread calling publish)
and the consumer will read all events in the queue and write them out.
Using the daemon mode of the thread handles flushing the queue on
main exit in python3; in python2.7 we handle the EOFError that results
when the publish thread calls to get() fails indicating the main thread
has exited.
The result is that the handler is no longer spawing a thread on each
publish event but rather creates a single thread when we start up
the reporter and we remove any additional use of separate locks and
flags as we only have a single Queue object and we're only calling
queue.put() from main thread and queue.get() from consuming thread.
Diffstat (limited to 'cloudinit/cmd/main.py')
-rw-r--r-- | cloudinit/cmd/main.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index c0edee18..4ea4fe7f 100644 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -877,9 +877,11 @@ def main(sysv_args=None): rname, rdesc, reporting_enabled=report_on) with args.reporter: - return util.log_time( + retval = util.log_time( logfunc=LOG.debug, msg="cloud-init mode '%s'" % name, get_uptime=True, func=functor, args=(name, args)) + reporting.flush_events() + return retval if __name__ == '__main__': |