How can I programmatically tell if my code is running in a model or not?

zach.ingrahamzach.ingraham Administrator, Moderator, Domino Posts: 34 admin
I want my code to behave differently while I'm developing it in Jupyterlab than it does when live as a model, but I don't want to manually edit a true/false variable every time. Is there a smart way to do this programmatically? 

Answers

  • mac.rogersmac.rogers Member, Domino Posts: 3
    edited May 20
    Here's a sample python snippet you can use to determine if you're in a model:
    import os 
    os.environ['HOSTNAME'].startswith('model')
    Domino injects a handful of useful environment variables into your runs - you can use the `HOSTNAME` environment variable to tell if you're inside a model. 

    In a Domino model, it will look like model-<hash>​, for example: 
    HOSTNAME=model-5cw2d57d36e0fb0107a9c5c2-7b4574f7b9-htv2r 

    In a Domino run, it will look like domino-run-<hash>, for example:
    HOSTNAME=domino-run-5ce2be3d43e0sb0107a9c5a9
    When running locally, it won't exist unless you've created it on your machine. 
Sign In or Register to comment.