'Hello World'
Last updated on 2025-08-22 | Edit this page
Overview
Questions
- How are the QMI contexts created?
Objectives
- Create a simple QMI context
“Hello world” context creation
Start up python
python
We are now in an interactive Python shell. Let’s start with importing QMI.
Presuming you had just installed QMI with Pip, this should just work without any issues. Let’s continue to creating a simple context called “hello_world”.
Now, your first QMI context has been started. You can verify this with
OUTPUT
QMI_context(name='hello_world')
A couple of remarks are in place already here. The context name is
with underscore (_) as spaces in the context names cause issues. So,
avoid those and also special letters like ‘!’, ‘@’, ‘#’, ‘$’ etc. We
also gave a second input parameter config_file=None
for the
call. This was actually optional as the default value for the parameter
is None
, but we wanted to illustrate with this that we
start a context without specifying a QMI configuration file. In that
case, QMI will create a simple configuration for the context. Now just
let’s stop the “hello_world” context.
We can confirm that the context has been stopped
OUTPUT
'*** No active QMI context ***'
And trying to a command like qmi.context()
now will give
an exception. Note that it is important always to stop your contexts.
Python does not always manage to clean up the QMI contexts properly,
especially when the context has plenty of things going on, if the
context is not manually stopped before. This can leave bogus QMI
contexts running on your system with e.g. some kind of task or
instrument control active.
- A QMI context is created using
qmi.start("<context_name>")
call - Always remember to stop the context with
qmi.stop()