[luci: 2/2] bz853151: "No object (name: translator) ..." due to private threading
by Jan Pokorný
commit 0363e2c12d6eee1152b7cd94367d3a9f7121153c
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Thu Aug 30 17:56:00 2012 +0200
bz853151: "No object (name: translator) ..." due to private threading
Possible alternative would be to use lazy_gettext to ensure real
evaluate-on-demand behavior (presumably back in the per-request
thread that comprises translator object by default).
Also, ricci_helpers.py: PWorker: fix a comment typo.
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
luci/lib/ricci_helpers.py | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/luci/lib/ricci_helpers.py b/luci/lib/ricci_helpers.py
index 03ebc43..23be6d3 100644
--- a/luci/lib/ricci_helpers.py
+++ b/luci/lib/ricci_helpers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2011 Red Hat, Inc.
+# Copyright (C) 2006-2012 Red Hat, Inc.
#
# This program is free software; you can redistribute
# it and/or modify it under the terms of version 2 of the
@@ -7,6 +7,9 @@
import threading
+import pylons
+from pylons.i18n.translation import _get_translator
+
from luci.lib.helpers import ugettext as _
from luci.model import DBSession
@@ -19,8 +22,9 @@ from luci.lib.ricci_communicator import RicciCommunicator
import logging
log = logging.getLogger(__name__)
+
class PWorker(threading.Thread):
- # triple := [ (host, port) function, *args ]
+ # triple := [ (host, port), function, *args ]
def __init__(self, mutex, ret, host_triples, cluster_members_only=False):
threading.Thread.__init__(self)
self.mutex = mutex
@@ -29,6 +33,14 @@ class PWorker(threading.Thread):
self.cluster_members_only = cluster_members_only
def run(self):
+ # see http://comments.gmane.org/gmane.comp.web.turbogears/46896
+ # this is stolen from the pylons test setup;
+ # it will make sure the gettext-stuff is working, that is
+ # we inject translator object to this private thread similarly
+ # as it is done by the framework in per-request threads
+ translator = _get_translator(None)
+ pylons.translator._push_object(translator)
+
while True:
self.mutex.acquire()
if len(self.triples) == 0:
@@ -67,6 +79,8 @@ class PWorker(threading.Thread):
self.ret[triple[0][0]] = r
self.mutex.release()
+ pylons.translator._pop_object()
+
def send_batch_parallel(triples, max_threads, cluster_members_only=False):
mutex = threading.RLock()
threads = list()
11 years, 8 months
[luci/bz853151: 2/2] bz853151: "No object (name: translator) ..." due to private threading
by Jan Pokorný
commit c669e6e0e68dd48b16f80a824e61d0b7ef6ba5f3
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Thu Aug 30 18:17:46 2012 +0200
bz853151: "No object (name: translator) ..." due to private threading
Possible alternative would be to use lazy_gettext to ensure real
evaluate-on-demand behavior (presumably back in the per-request
thread that comprises translator object by default).
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
luci/lib/ricci_helpers.py | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/luci/lib/ricci_helpers.py b/luci/lib/ricci_helpers.py
index 5a8e9ae..16a90d4 100644
--- a/luci/lib/ricci_helpers.py
+++ b/luci/lib/ricci_helpers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2011 Red Hat, Inc.
+# Copyright (C) 2006-2012 Red Hat, Inc.
#
# This program is free software; you can redistribute
# it and/or modify it under the terms of version 2 of the
@@ -7,6 +7,9 @@
import threading
+import pylons
+from pylons.i18n.translation import _get_translator
+
from luci.lib.helpers import ugettext as _
from luci.model import DBSession
@@ -19,6 +22,7 @@ from luci.lib.ricci_communicator import RicciCommunicator
import logging
log = logging.getLogger(__name__)
+
class PWorker(threading.Thread):
# triple := [ (host, port), function, *args ]
def __init__(self, mutex, ret, host_triples, cluster_members_only=False):
@@ -29,6 +33,14 @@ class PWorker(threading.Thread):
self.cluster_members_only = cluster_members_only
def run(self):
+ # see http://comments.gmane.org/gmane.comp.web.turbogears/46896
+ # this is stolen from the pylons test setup;
+ # it will make sure the gettext-stuff is working, that is
+ # we inject translator object to this private thread similarly
+ # as it is done by the framework in per-request threads
+ translator = _get_translator()
+ pylons.translator._push_object(translator)
+
while True:
self.mutex.acquire()
if len(self.triples) == 0:
@@ -67,6 +79,8 @@ class PWorker(threading.Thread):
self.ret[triple[0][0]] = r
self.mutex.release()
+ pylons.translator._pop_object()
+
def send_batch_parallel(triples, max_threads, cluster_members_only=False):
mutex = threading.RLock()
threads = list()
11 years, 8 months
[luci/bz853151: 1/2] ricci_helpers.py: PWorker: fix a comment typo
by Jan Pokorný
commit 5755a2e9abda65481c77095442bee7479ed56c5f
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Thu Aug 30 17:56:00 2012 +0200
ricci_helpers.py: PWorker: fix a comment typo
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
luci/lib/ricci_helpers.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/luci/lib/ricci_helpers.py b/luci/lib/ricci_helpers.py
index 03ebc43..5a8e9ae 100644
--- a/luci/lib/ricci_helpers.py
+++ b/luci/lib/ricci_helpers.py
@@ -20,7 +20,7 @@ import logging
log = logging.getLogger(__name__)
class PWorker(threading.Thread):
- # triple := [ (host, port) function, *args ]
+ # triple := [ (host, port), function, *args ]
def __init__(self, mutex, ret, host_triples, cluster_members_only=False):
threading.Thread.__init__(self)
self.mutex = mutex
11 years, 8 months
[luci] (2 commits) Created branch bz853151
by Jan Pokorný
The branch 'bz853151' was created.
Summary of new commits:
5755a2e... ricci_helpers.py: PWorker: fix a comment typo
c669e6e... bz853151: "No object (name: translator) ..." due to privat
11 years, 8 months
[luci/bz853151: 2/2] bz853151: "No object (name: translator) ..." due to private threading
by Jan Pokorný
commit 3b15d652cb557dd10383ec923d5459fb52bb80de
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Thu Aug 30 18:17:46 2012 +0200
bz853151: "No object (name: translator) ..." due to private threading
Possible alternative would be to use lazy_gettext to ensure real
evaluate-on-demand behavior (presumably back in the per-request
thread that comprises translator object by default).
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
luci/lib/ricci_helpers.py | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/luci/lib/ricci_helpers.py b/luci/lib/ricci_helpers.py
index 5a8e9ae..4f1035c 100644
--- a/luci/lib/ricci_helpers.py
+++ b/luci/lib/ricci_helpers.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2006-2011 Red Hat, Inc.
+# Copyright (C) 2006-2012 Red Hat, Inc.
#
# This program is free software; you can redistribute
# it and/or modify it under the terms of version 2 of the
@@ -7,6 +7,9 @@
import threading
+import pylons
+from pylons.i18n.translation import _get_translator
+
from luci.lib.helpers import ugettext as _
from luci.model import DBSession
@@ -19,6 +22,7 @@ from luci.lib.ricci_communicator import RicciCommunicator
import logging
log = logging.getLogger(__name__)
+
class PWorker(threading.Thread):
# triple := [ (host, port), function, *args ]
def __init__(self, mutex, ret, host_triples, cluster_members_only=False):
@@ -29,6 +33,14 @@ class PWorker(threading.Thread):
self.cluster_members_only = cluster_members_only
def run(self):
+ # see http://comments.gmane.org/gmane.comp.web.turbogears/46896
+ # this is stolen from the pylons test setup;
+ # it will make sure the gettext-stuff is working, that is
+ # we inject translator object to this private thread similarly
+ # as it is done by the framework in per-request threads
+ translator = _get_translator()
+ pylons.translator._push_object(translator)
+
while True:
self.mutex.acquire()
if len(self.triples) == 0:
@@ -62,11 +74,14 @@ class PWorker(threading.Thread):
r['err_msg'] = str(e)
r['ricci'] = None
log.error('%s' % str(e))
+ pylons.translator._pop_object()
self.mutex.acquire()
self.ret[triple[0][0]] = r
self.mutex.release()
+ pylons.translator._pop_object()
+
def send_batch_parallel(triples, max_threads, cluster_members_only=False):
mutex = threading.RLock()
threads = list()
11 years, 8 months
[luci/bz853151: 1/2] ricci_helpers.py: PWorker: fix a comment typo
by Jan Pokorný
commit 5755a2e9abda65481c77095442bee7479ed56c5f
Author: Jan Pokorny <jpokorny(a)redhat.com>
Date: Thu Aug 30 17:56:00 2012 +0200
ricci_helpers.py: PWorker: fix a comment typo
Signed-off-by: Jan Pokorny <jpokorny(a)redhat.com>
luci/lib/ricci_helpers.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/luci/lib/ricci_helpers.py b/luci/lib/ricci_helpers.py
index 03ebc43..5a8e9ae 100644
--- a/luci/lib/ricci_helpers.py
+++ b/luci/lib/ricci_helpers.py
@@ -20,7 +20,7 @@ import logging
log = logging.getLogger(__name__)
class PWorker(threading.Thread):
- # triple := [ (host, port) function, *args ]
+ # triple := [ (host, port), function, *args ]
def __init__(self, mutex, ret, host_triples, cluster_members_only=False):
threading.Thread.__init__(self)
self.mutex = mutex
11 years, 8 months