Nir Soffer has uploaded a new change for review.
Change subject: concurrent: Add support for target function kwargs ......................................................................
concurrent: Add support for target function kwargs
Turns out we pass kwargs to some threads, so we must support this syntax.
Change-Id: I5bcc24686279f9511baa83e64ac186533513cbd3 Signed-off-by: Nir Soffer nsoffer@redhat.com --- M lib/vdsm/concurrent.py M tests/concurrentTests.py 2 files changed, 19 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/45470/1
diff --git a/lib/vdsm/concurrent.py b/lib/vdsm/concurrent.py index 5a9df85..6de35c7 100644 --- a/lib/vdsm/concurrent.py +++ b/lib/vdsm/concurrent.py @@ -151,7 +151,7 @@ return results
-def thread(func, args=(), name=None, daemon=True, logger=None): +def thread(func, args=(), kwargs=None, name=None, daemon=True, logger=None): """ Create a thread for runnning func with args.
@@ -161,6 +161,8 @@
args Arguments to pass to func
+ kwargs Keyword arguments to pass to func + name If set, set thread name.
daemon If True, create a daemon thread. @@ -168,9 +170,12 @@ logger If set, unhandled exception will be logged on this logger. Otherwise the root logger will be used. """ + if kwargs is None: + kwargs = {} + @utils.traceback(on=logger) def run(): - return func(*args) + return func(*args, **kwargs)
thread = threading.Thread(target=run, name=name) thread.daemon = daemon diff --git a/tests/concurrentTests.py b/tests/concurrentTests.py index 62ca833..d6c212a 100644 --- a/tests/concurrentTests.py +++ b/tests/concurrentTests.py @@ -229,3 +229,15 @@ t.start() t.join() self.assertEqual((1, 2, 3), self.args) + + def test_pass_kwargs(self): + self.kwargs = () + + def run(**kwargs): + self.kwargs = kwargs + + kwargs = {'a': 1, 'b': 2} + t = concurrent.thread(run, kwargs=kwargs) + t.start() + t.join() + self.assertEqual(kwargs, self.kwargs)
automation@ovirt.org has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1: Verified+1
Ido Barkan has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1: Code-Review+1
Francesco Romani has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1: Code-Review+1
Piotr Kliczewski has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1: Code-Review+1
Nir Soffer has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 1: Code-Review+2
Everyone seems happy, approving.
automation@ovirt.org has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 2:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 2: Code-Review+2
This version is a rebase on current master without any code change. Copying score.
Nir Soffer has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 2: Verified+1
Dan Kenigsberg has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 2: Code-Review+2
Dan Kenigsberg has submitted this change and it was merged.
Change subject: concurrent: Add support for target function kwargs ......................................................................
concurrent: Add support for target function kwargs
Turns out we pass kwargs to some threads, so we must support this syntax.
Change-Id: I5bcc24686279f9511baa83e64ac186533513cbd3 Relates-To: https://bugzilla.redhat.com/1141422 Signed-off-by: Nir Soffer nsoffer@redhat.com Reviewed-on: https://gerrit.ovirt.org/45470 Continuous-Integration: Jenkins CI Reviewed-by: Dan Kenigsberg danken@redhat.com --- M lib/vdsm/concurrent.py M tests/concurrentTests.py 2 files changed, 19 insertions(+), 2 deletions(-)
Approvals: Nir Soffer: Verified; Looks good to me, approved Jenkins CI: Passed CI tests Dan Kenigsberg: Looks good to me, approved
automation@ovirt.org has posted comments on this change.
Change subject: concurrent: Add support for target function kwargs ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Set MODIFIED::IGNORE, no Bug-Url found.
vdsm-patches@lists.fedorahosted.org