Last active
March 19, 2019 08:38
-
-
Save Windsooon/2b50f6c1d2314885cf7a6a24373c1f2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
notify
. Plugins get all notifications automatically via thedef on_notify(self, notification)
callback, defined inPlugin
.ipc_sub_url
instead ofipc_pub_url
. Also, the pull_socket should not be required here.