Use the tdnb.exit() function to exit a notebook with a message.
As touch based in the previous section, tdnb.exit() is a utility which has power to stop the execution of notebook when run from another notebook and has ability to send a message to its caller notebook. So, caller notebook effectively makes use of the message and take decisions appropriately.
Required Parameters
- message
- Specifies the message to be returned from the executed notebook to the executor notebook.
Example 1
Consider the same example used for tdnb.run_notebook(). However, in this example, check whether logger is executed or not from notebook1.ipynb1 using tdnb.exit().
content of logger_notebook.ipynb
import logging
logger = logging.getLogger('LoggerNotebook')
logging.getLogger().setLevel(logging.INFO)
from teradatamlwidgets import tdnb
tdnb.text('log message', 'message', 'LogMessage:'
logger.warning(tdnb.get('log_message'))
tdnb.exit("logged")
content of notebook1.ipynb
from teradatamlwidgets import tdnb
tdnb.run_notebook('logger_notbook.ipynb', arguments={'log_message': 'Message1'})
Example 2
Design two notebooks:
- Design a notebook with name test_even_odd.ipynb to look for a number, decide whether it is even or odd and exist with message as EVEN or ODD.
- Design another notebook notebook1.ipynb to pass a number to test_even_odd.ipynb and retrieve message from it.
Content of test_even_odd.iypnb
from teradatamlwidgets import tdnb
tdnb.text('number', '0', 'Number'
# Retrieve the value. Parse the value to int
# text field always stores in string format
num = int(tdnb.get('number'))
if num%2 == 0
tdnb.exit('EVEN')
else:
tdnb.exit('ODD')
Content of notebook1.iypnb
from teradatamlwidgets import tdnb
tdnb.runbook('test_even_odd.ipynb', arguments={'number': '5'})
tdnb.runbook('test_even_odd.ipynb', arguments={'number': '4'})