Skip to content

Instantly share code, notes, and snippets.

@Windsooon
Last active March 19, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windsooon/2b50f6c1d2314885cf7a6a24373c1f2c to your computer and use it in GitHub Desktop.
Save Windsooon/2b50f6c1d2314885cf7a6a24373c1f2c to your computer and use it in GitHub Desktop.
class Pupil_Recording(System_Plugin_Base):
"""
Collect log in recording
"""
def __init__(self, g_pool):
super().__init__(g_pool)
self.order = 0.08
self.notify_sub = zmq_tools.Msg_Receiver(
zmq_ctx, ipc_sub_url, topics=("notify",))
def recent_events(self, events):
"""
We get notifications from all plugins, then we search `recording.started`, use another thread
to handle the log.
"""
new_notifications = []
while self.notify_sub.new_data:
t, n = self.notify_sub.recv()
new_notifications.append(n)
# notify each plugin if there are new notifications:
for n in new_notifications:
handle_notifications(n)
def pub_handle():
"""
Run in another thread to collect recording
"""
sub = zmq_tools.Msg_Receiver(zmq_ctx, ipc_sub_url, topics=("logging",))
while True:
topic, msg = sub.recv()
record = logging.makeLogRecord(msg)
logger.handle(record)
def handle_notifications(noti):
subject = n["subject"]
if subject == "recording.started":
pub = Thread(target=pub_handle, args=(ipc_pub_url, pull_socket))
pub.setDaemon(True)
pub.start()
elif subject == "recording.stop":
pub.stop()
@papr
Copy link

papr commented Mar 19, 2019

  1. There is no need to subscribe to notify. Plugins get all notifications automatically via the def on_notify(self, notification) callback, defined in Plugin.
  2. Line 38: It should be ipc_sub_url instead of ipc_pub_url. Also, the pull_socket should not be required here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment