Programmatically determine if running in DSX

113 views Asked by At

How can I programmatically determine if the python code in my notebook is running under DSX?

I'd like to be able to do different things under a local Jupyter notebook vs. DSX.

2

There are 2 answers

1
Philipp Langer On BEST ANSWER

While the method presented in another answer (look for specific environment variables) works today, it may stop working in the future. This is not an official API that DSX exposes. It will obviously also not work if somebody decides to set these environment variables on their non-DSX system.

My take on this is that "No, there is no way to reliably determine whether the notebook is running on DSX".

In general, (in my opinion) notebooks are not really designed as artifacts that you can arbitrarily deploy anywhere; there will always need to be someone wearing the "application developer" hat and transform them - how to do that, you could put into a markdown cell inside the notebook.

5
Sumit Goyal On

You can print your environment or look for some specific environment variable. I am sure you will find some differences.

For example:

import os
if os.environ.get('SERVICE_CALLER'):
  print ('In DSX')    
else:
  print ('Not in DSX')