Repository: ManiacalLabs/BiblioPixel
Pull request #847 (2018-06-09 14:29:14)

Rename project/event_queue to project/edit_queue
Another "change the code to match the documentation" commit.  

It isn't a queue of "events" at all - one incoming event can trigger multiple of these!  These are changes to the project, so they are an "edit" - pending a better name.  :-D

(Also, we actually use `threading.Event`, which means we have two unrelated `Event`s.)

adammhaile: +1

On Sat, Jun 9, 2018 at 10:29 AM Tom Swirly <notifications@github.com> wrote:

> Another "change the code to match the documentation" commit.
>
> It isn't a queue of "events" at all - one incoming event can trigger
> multiple of these! These are changes to the project, so they are an "edit"
> - pending a better name. :-D
>
> (Also, we actually use threading.Event, which means we have two unrelated
> Events.)
> ------------------------------
> You can view, comment on, or merge this pull request online at:
>
>   https://github.com/ManiacalLabs/BiblioPixel/pull/847
> Commit Summary
>
>    - Rename project/event_queue to project/edit_queue
>
> File Changes
>
>    - *M* bibliopixel/animation/animation.py
>    <https://github.com/ManiacalLabs/BiblioPixel/pull/847/files#diff-0>
>    (2)
>    - *M* bibliopixel/control/queued_address.py
>    <https://github.com/ManiacalLabs/BiblioPixel/pull/847/files#diff-1>
>    (10)
>    - *R* bibliopixel/project/edit_queue.py
>    <https://github.com/ManiacalLabs/BiblioPixel/pull/847/files#diff-2>
>    (34)
>    - *M* bibliopixel/project/project.py
>    <https://github.com/ManiacalLabs/BiblioPixel/pull/847/files#diff-3>
>    (16)
>    - *M* test/bibliopixel/control/queued_address_test.py
>    <https://github.com/ManiacalLabs/BiblioPixel/pull/847/files#diff-4>
>    (6)
>
> Patch Links:
>
>    - https://github.com/ManiacalLabs/BiblioPixel/pull/847.patch
>    - https://github.com/ManiacalLabs/BiblioPixel/pull/847.diff
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/ManiacalLabs/BiblioPixel/pull/847>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AA6a6ncd0UTKvcvKjFFlSxFIHIhaybURks5t69u7gaJpZM4UhWwq>
> .
>


Patch:
diff --git a/bibliopixel/animation/animation.py b/bibliopixel/animation/animation.py
index dded550..8fcc40d 100644
--- a/bibliopixel/animation/animation.py
+++ b/bibliopixel/animation/animation.py
@@ -90,7 +90,7 @@ class Animation(object):
         pass.
 
         The ``Project`` writes over this method, for the top-level animation
-        only, in order to drain its event_queue at a moment where no rendering
+        only, in order to drain its edit_queue at a moment where no rendering
         is happening to avoid race conditions.
         """
         pass
diff --git a/bibliopixel/control/queued_address.py b/bibliopixel/control/queued_address.py
index 44c595a..d36ad02 100644
--- a/bibliopixel/control/queued_address.py
+++ b/bibliopixel/control/queued_address.py
@@ -5,10 +5,10 @@ from . receiver import Receiver
 class QueuedAddress(Receiver):
     """
     A `QueuedAddress` is a `Receiver` which sets `Address`es, perhaps using an
-    an optional `EventQueue`.
+    an optional `EditQueue`.
 
     When the `set_root` method is called, `QueuedAddress` searches
-    down through the address and stores the most recent `event_queue`
+    down through the address and stores the most recent `edit_queue`
     method it finds.
 
     """
@@ -22,7 +22,7 @@ class QueuedAddress(Receiver):
         self.subroot = root
 
         for segment in self.address.segments:
-            self.queue = getattr(self.subroot, 'event_queue', self.queue)
+            self.queue = getattr(self.subroot, 'edit_queue', self.queue)
             if segment is not self.last_segment:
                 self.subroot = segment.get(self.subroot)
                 if self.subroot is None:
@@ -33,11 +33,11 @@ class QueuedAddress(Receiver):
     def receive(self, msg):
         """
         Receives a message, and either sets it immediately, or puts it on the
-        event queue if there is one.
+        edit queue if there is one.
 
         """
         if self.queue:
-            self.queue.put_event(self._set, msg)
+            self.queue.put_edit(self._set, msg)
         else:
             self._set(msg)
 
diff --git a/bibliopixel/project/event_queue.py b/bibliopixel/project/edit_queue.py
similarity index 53%
rename from bibliopixel/project/event_queue.py
rename to bibliopixel/project/edit_queue.py
index f114434..344d4bd 100644
--- a/bibliopixel/project/event_queue.py
+++ b/bibliopixel/project/edit_queue.py
@@ -1,19 +1,19 @@
 import functools, queue
 
 
-class EventQueue(queue.Queue):
+class EditQueue(queue.Queue):
     """
-    ``Event``s are thread-unsafe operations to be executed later at a
+    ``Edits``s are thread-unsafe operations to be executed later at a
     thread-safe time.  In the animation loop, this happens in
     :py:method:`bibliopixel.animation.Animation.preframe_callback`.
 
-    The typical `Event` is a change to some parameter of an animation,
+    The typical `Edit` is a change to some parameter of an animation,
     but in general is represented by a call to a function with fixed parameters.
     """
 
-    def put_event(self, f, *args, **kwds):
+    def put_edit(self, f, *args, **kwds):
         """
-        Defer an event to run on the EventQueue.
+        Defer an edit to run on the EditQueue.
 
         :param callable f: The function to be called
         :param tuple args: Positional arguments to the function
@@ -22,32 +22,32 @@ class EventQueue(queue.Queue):
         """
         self.put_nowait(functools.partial(f, *args, **kwds))
 
-    def get_and_run_events(self):
+    def get_and_run_edits(self):
         """
-        Get all the events in the queue, then execute them.
+        Get all the edits in the queue, then execute them.
 
-        The algorithm gets all events, and then executes all of them.  It does
-        *not* pull off one event, execute, repeat until the queue is empty, and
+        The algorithm gets all edits, and then executes all of them.  It does
+        *not* pull off one edit, execute, repeat until the queue is empty, and
         that means that the queue might not be empty at the end of
-        ``run_events``, because new events might have entered the queue
-        while the previous events are being executed.
+        ``run_edits``, because new edits might have entered the queue
+        while the previous edits are being executed.
 
-        This has the advantage that if events enter the queue faster than they
-        can be processed, ``get_and_run_events`` won't go into an infinite loop,
+        This has the advantage that if edits enter the queue faster than they
+        can be processed, ``get_and_run_edits`` won't go into an infinite loop,
         but rather the queue will grow unboundedly, which that can be
         detected, and mitigated and reported on - or if Queue.maxsize is
-        set, `bp` will report a fairly clear error and just dump the events
+        set, `bp` will report a fairly clear error and just dump the edits
         on the ground.
         """
         if self.empty():
             return
 
-        events = []
+        edits = []
         while True:
             try:
-                events.append(self.get_nowait())
+                edits.append(self.get_nowait())
             except queue.Empty:
                 break
 
-        for e in events:
+        for e in edits:
             e()
diff --git a/bibliopixel/project/project.py b/bibliopixel/project/project.py
index 556a5c0..5fd658f 100644
--- a/bibliopixel/project/project.py
+++ b/bibliopixel/project/project.py
@@ -1,9 +1,9 @@
 import os, queue, threading, weakref
 from . import (
-    attributes, construct, cleanup, defaults, event_queue, load, recurse)
+    attributes, construct, cleanup, defaults, edit_queue, load, recurse)
 from .. util import exception, log
 
-EVENT_QUEUE_MAXSIZE = 1000
+EDIT_QUEUE_MAXSIZE = 1000
 NO_DATATYPE_ERROR = 'No "datatype" field in section "%s"'
 
 
@@ -27,9 +27,9 @@ class Project:
 
     def __init__(self, *,
                  drivers, layout, maker, path, animation, controls,
-                 event_queue_maxsize=EVENT_QUEUE_MAXSIZE, **kwds):
+                 edit_queue_maxsize=EDIT_QUEUE_MAXSIZE, **kwds):
         """
-        :param int event_queue_maxsize: maxsize parameter to queue.Queue.
+        :param int edit_queue_maxsize: maxsize parameter to queue.Queue.
             0 means an unbounded queue.
         """
         def create(root, name):
@@ -57,13 +57,13 @@ class Project:
         self.animation = create(animation, 'animation')
         self.running = False
 
-        eq = event_queue.EventQueue(maxsize=event_queue_maxsize)
-        self.layout.event_queue = self.animation.event_queue = eq
-        self.animation.preframe_callback = eq.get_and_run_events
+        eq = edit_queue.EditQueue(maxsize=edit_queue_maxsize)
+        self.layout.edit_queue = self.animation.edit_queue = eq
+        self.animation.preframe_callback = eq.get_and_run_edits
 
         # Unfortunately, the whole animation cycle is controlled by methods on
         # the topmost animation - but we need to get called back at a certain
-        # point in that animation cycle in order to run the event queue safely -
+        # point in that animation cycle in order to run the edit queue safely -
         # and animations don't know about the Project!
         #
         # So the monkey-patch above.  Ugly.  When we rewrite the


Test patch:
diff --git a/test/bibliopixel/control/queued_address_test.py b/test/bibliopixel/control/queued_address_test.py
index 319faf5..2a6d448 100644
--- a/test/bibliopixel/control/queued_address_test.py
+++ b/test/bibliopixel/control/queued_address_test.py
@@ -1,6 +1,6 @@
 import unittest
 from bibliopixel.control.queued_address import QueuedAddress
-from bibliopixel.project.event_queue import EventQueue
+from bibliopixel.project.edit_queue import EditQueue
 
 
 class Base:
@@ -15,7 +15,7 @@ class Base:
     class BarQ(Bar):
         def __init__(self):
             super().__init__()
-            self.event_queue = EventQueue()
+            self.edit_queue = EditQueue()
 
     class Baz:
         def __init__(self):
@@ -43,5 +43,5 @@ class QueuedAddressTest(unittest.TestCase):
         self.assertEqual(qa.get(), 12)
         qa.receive(('hello',))
         self.assertEqual(qa.get(), 12)
-        test.baz.barq.event_queue.get_and_run_events()
+        test.baz.barq.edit_queue.get_and_run_edits()
         self.assertEqual(qa.get(), 'hello')