From 58603671c21b0af30d0d52fec862c5843c6e50d0 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 9 Aug 2018 13:45:55 +0200 Subject: Cleanup of class scoped variables After bug described in OS#3456 and fixed in last commit, let's categorize and place variables in its correct plac to avoid similar issus. We leave under the class keyword (class scoped variables) the attributes which are to be used as static class attributes. All other ones are initialized during __init__(). This way w avoid scenarios in which while using an object from an instance attribute we end up reading a class scoped variable which is shared among all instances. Change-Id: I5ad4cac34a9f49eaf42966c01c9c5a4d3f3e9dc8 --- src/osmo_gsm_tester/event_loop.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/osmo_gsm_tester/event_loop.py') diff --git a/src/osmo_gsm_tester/event_loop.py b/src/osmo_gsm_tester/event_loop.py index 0f647c2..fe88ef4 100644 --- a/src/osmo_gsm_tester/event_loop.py +++ b/src/osmo_gsm_tester/event_loop.py @@ -23,10 +23,12 @@ from gi.repository import GLib, GObject from . import log class DeferredHandling: - defer_queue = [] + + def __init__(self): + self.defer_queue = [] def handle_queue(self): - while DeferredHandling.defer_queue: + while self.defer_queue: handler, args, kwargs = self.defer_queue.pop(0) handler(*args, **kwargs) @@ -34,10 +36,10 @@ class DeferredHandling: self.defer_queue.append((handler, args, kwargs)) class WaitRequest: - timeout_ack = False - condition_ack = False def __init__(self, condition, condition_args, condition_kwargs, timeout, timestep): + self.timeout_ack = False + self.condition_ack = False self.timeout_started = time.time() self.timeout = timeout self.condition = condition @@ -53,12 +55,9 @@ class WaitRequest: self.timeout_ack = True class EventLoop: - poll_funcs = [] - gloop = None - gctx = None - deferred_handling = None def __init__(self): + self.poll_funcs = [] self.gloop = GLib.MainLoop() self.gctx = self.gloop.get_context() self.deferred_handling = DeferredHandling() -- cgit v1.2.3