grc: Add a startup event to the Python make template

Code merged into the Python Mako template, e.g., from YML files,
may need to wait for the top block to be initialized before
referencing other generated objects. An event that is set just
after tb.start() in main() should be sufficient.

Signed-off-by: Jeff Long <willcode4@gmail.com>
This commit is contained in:
Jeff Long 2024-05-23 12:05:06 -04:00
parent 38435f7fe9
commit 697fcbf14c
2 changed files with 9 additions and 2 deletions

View File

@ -161,6 +161,9 @@ gr.io_signature.makev(${len(io_sigs)}, ${len(io_sigs)}, [${', '.join(size_strs)}
self._lock = threading.RLock()
% endif
% if not generate_options.startswith('hb'):
self.flowgraph_started = threading.Event()
% endif
########################################################
##Create Parameters
## Set the parameter to a property of self.
@ -335,6 +338,7 @@ def main(top_block_cls=${class_name}, options=None):
${'snippets_main_after_init(tb)' if snippets['main_after_init'] else ''}
% if flow_graph.get_option('run'):
tb.start(${flow_graph.get_option('max_nouts') or ''})
tb.flowgraph_started.set()
% endif
${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% if flow_graph.get_option('qt_qss_theme'):
@ -367,6 +371,7 @@ def main(top_block_cls=${class_name}, options=None):
${'snippets_main_after_init(tb)' if snippets['main_after_init'] else ''}
try:
tb.start()
tb.flowgraph_started.set()
${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
bokehgui.utils.run_server(tb, sizing_mode = "${flow_graph.get_option('sizing_mode')}", widget_placement = ${flow_graph.get_option('placement')}, window_size = ${flow_graph.get_option('window_size')})
finally:
@ -393,6 +398,7 @@ def main(top_block_cls=${class_name}, options=None):
% if flow_graph.get_option('run_options') == 'prompt':
tb.start(${ flow_graph.get_option('max_nouts') or '' })
tb.flowgraph_started.set()
${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% for m in monitors:
% if m.params['en'].get_value() == 'True':
@ -407,6 +413,7 @@ def main(top_block_cls=${class_name}, options=None):
## ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
% elif flow_graph.get_option('run_options') == 'run':
tb.start(${flow_graph.get_option('max_nouts') or ''})
tb.flowgraph_started.set()
${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% for m in monitors:
% if m.params['en'].get_value() == 'True':

View File

@ -163,8 +163,8 @@ class TopBlockGenerator(object):
imports.append('import os')
imports.append('import sys')
if fg.get_option('thread_safe_setters'):
imports.append('import threading')
# Used by thread_safe_setters and startup Event
imports.append('import threading')
def is_duplicate(l):
if (l.startswith('import') or l.startswith('from')) and l in seen: