From fd7081830c6fe3811fc85ca1ffb495a5604bf621 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 12 Nov 2019 19:43:04 +0800 Subject: [PATCH] remove fire_and_forget (moved to sipyco) --- artiq/protocols/__init__.py | 0 artiq/protocols/fire_and_forget.py | 51 ------------------------------ artiq/test/test_fire_and_forget.py | 17 ---------- 3 files changed, 68 deletions(-) delete mode 100644 artiq/protocols/__init__.py delete mode 100644 artiq/protocols/fire_and_forget.py delete mode 100644 artiq/test/test_fire_and_forget.py diff --git a/artiq/protocols/__init__.py b/artiq/protocols/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/artiq/protocols/fire_and_forget.py b/artiq/protocols/fire_and_forget.py deleted file mode 100644 index 61b2a4aa2..000000000 --- a/artiq/protocols/fire_and_forget.py +++ /dev/null @@ -1,51 +0,0 @@ -import threading -import logging -import inspect - - -logger = logging.getLogger(__name__) - - -class FFProxy: - """Proxies a target object and runs its methods in the background. - - All method calls to this object are forwarded to the target and executed - in a background thread. Method calls return immediately. Exceptions from - the target method are turned into warnings. At most one method from the - target object may be executed in the background; if a new call is - submitted while the previous one is still executing, a warning is printed - and the new call is dropped. - - This feature is typically used to wrap slow and non-critical RPCs in - experiments. - """ - def __init__(self, target): - self.target = target - - valid_methods = inspect.getmembers(target, inspect.ismethod) - self._valid_methods = {m[0] for m in valid_methods} - self._thread = None - - def ff_join(self): - """Waits until any background method finishes its execution.""" - if self._thread is not None: - self._thread.join() - - def __getattr__(self, k): - if k not in self._valid_methods: - raise AttributeError - def run_in_thread(*args, **kwargs): - if self._thread is not None and self._thread.is_alive(): - logger.warning("skipping fire-and-forget call to %r.%s as " - "previous call did not complete", - self.target, k) - return - def thread_body(): - try: - getattr(self.target, k)(*args, **kwargs) - except: - logger.warning("fire-and-forget call to %r.%s raised an " - "exception:", self.target, k, exc_info=True) - self._thread = threading.Thread(target=thread_body) - self._thread.start() - return run_in_thread diff --git a/artiq/test/test_fire_and_forget.py b/artiq/test/test_fire_and_forget.py deleted file mode 100644 index fb8e67555..000000000 --- a/artiq/test/test_fire_and_forget.py +++ /dev/null @@ -1,17 +0,0 @@ -import unittest - -from artiq.protocols import fire_and_forget - - -class FireAndForgetCase(unittest.TestCase): - def _set_ok(self): - self.ok = True - - def test_fire_and_forget(self): - self.ok = False - p = fire_and_forget.FFProxy(self) - p._set_ok() - with self.assertRaises(AttributeError): - p.non_existing_method - p.ff_join() - self.assertTrue(self.ok)