Scissors in console vs module

Hi,
I am writing a module where I need to use threshold and scissors from the Segment Editor.

If I run the following code in the console it works as expected and I can draw the ROI but when I copy the code to my module, the thresholding is done and the cursor changes to the scissor icon but I cannot create the ROI. Any suggestions?

masterVolumeNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLScalarVolumeNode')

# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)

# Create temporary segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setSourceVolumeNode(masterVolumeNode)

addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("t_stomach")
segmentEditorNode.SetSelectedSegmentID(addedSegmentID)

segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold","0")
effect.self().onApply()

segmentEditorWidget.setActiveEffectByName("Scissors")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("Operation","EraseOutside")
effect.setParameter("Shape","FreeForm")

If I put my code in a function on the console I have the same behavior so I need to pause for user input inside the function. What is the best way to do that?