Hi -
For this issue and probably your other question you could study how the event observers work in Slicer to make everything asynchronous. E.g. this example has callbacks for markup interactions. Your code shouldn’t block, but should instead be driven by callbacks when events occur.