<jupyter_start><jupyter_text>Test interfacing with a remote DRP frameworkCreated: 2020-04-17, skwok<jupyter_code>import sys
import time
import glob

from interface import FrameworkInterface, Arguments, Event, Framework, ConfigClass<jupyter_output><empty_output><jupyter_text>Some help functions<jupyter_code>def print_pending_events (drpif):
    """
    Prints pending events, ie. events that are in the event queue.
    """
    if drpif.is_queue_ok():
        events = drpif.pending_events()
        for pe in events:
            print (pe)
    else:
        print ("Pending events: Queue not available", drpif.queue)
def ingest_files (drpif, filelist):
    """
    Ingests 'next_file' events into the event queue.    
    """
    if drpif.is_queue_ok():
        for f in files:
            event = Event ("next_file", Arguments (name=f))
            print ("Adding ", f)
            drpif.add_event(event)
    else:
        print ("Ingest files: Queue not available", drpif.queue)<jupyter_output><empty_output><jupyter_text>Get the DRPF interface to the queue managerFirst, check is the queue is available, ie. if the queue manager process is already running.If not, then start the queue manager process.<jupyter_code>cfg = ConfigClass ("multi_config.cfg")
drpf_IF = FrameworkInterface(cfg)

if not drpf_IF.is_queue_ok():
    print ("Staring the queue manager")
    res = drpf_IF.start_event_queue ()
    if res is None:
        print ("Faile to start queue")

#
# Check again
#
if not drpf_IF.is_queue_ok():
    print ("Failed to get remote event queue")
else:
    print ("Event queue ready")<jupyter_output><empty_output><jupyter_text>Add some data to the event queueCheck if DRPF queue manager is alivethen ingest some data filesand print the pending events<jupyter_code>files = glob.glob("../../keckdrpframework/unit_tests/test_files/*.fits")
ingest_files(drpf_IF, files)<jupyter_output><empty_output><jupyter_text>Show how many events are in the queue<jupyter_code>print_pending_events(drpf_IF)<jupyter_output><empty_output><jupyter_text>Handle the eventsAt this point, there are two choices:- Start a process or multiple processes to handle the events- Invoke main_loop here The pipeline used in this notebook is the example pipeline included in the repository.Run the following command in a xterm to process the data:```   cd ../../keckdrpframework/example   sh runTest_harness2.sh -c config.cfg```<jupyter_code>#
# Choice #2, Invoking main_loop.
#
from keckdrpframework.examples.pipelines.fits2png_pipeline import Fits2pngPipeline
drpf = Framework(Fits2pngPipeline, "multi_config.cfg")
drpf.main_loop()<jupyter_output><empty_output><jupyter_text>Stop the queue manager<jupyter_code>if drpf_IF.is_queue_ok():
    drpf_IF.stop_event_queue()
    print ("Queue manager stopped")
else:
    print ("Queue manager already stopped")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09322625698324022, 'fraction_numerical': 0.004539106145251397, 'mean_word_length': 4.584795321637427, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '192579', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 922, 'n_tokens_neox': 900, 'n_words': 266, 'path': 'keckdrpframework/tools/DRPF-remote-Interface.ipynb', 'repo_name': 'Keck-DataReductionPipelines/keckdrpframework', 'size': '2864'}