I am trying to lower the time to capture a still image from the Pi camera (I have a V2 and HQ). To this end, I have found my way to the PiCamera 1.13 docs, specifically chapter 16 dealing with the MMAL object. I tried following the example code given between 16.1.1 and 16.1.7, which seems to be a basic set-up and capture.
I reduced the code to the minimum I thought would work; there is a lot of input and output confirmation I removed. Here is the code:

 from picamera import mmal, mmalobj as mo
 import io
 
 def image_callback(port, buf):
 output.write(buf.data)
 return bool(buf.flags & mmal.MMAL_BUFFER_HEADER_FLAG_FRAME_END)

 camera = mo.MMALCamera()
 preview = mo.MMALRenderer()

 camera.outputs[2].format = mmal.MMAL_ENCODING_RGB24
 camera.outputs[2].framesize = (640, 480)
 camera.outputs[2].commit()
 camera.outputs[2]
 camera.outputs[2].enable()
 camera.outputs[2].disable()

 output = io.open('image.data', 'wb')

 camera.outputs[2].enable(image_callback)
 output.tell()

 camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = True
 camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = False
 output.tell()
 camera.outputs[2].disable()
 output.close()

This code runs without error from a file, cam_test.py, but produces the file image.data of size 0 bytes. However, when the code is run interactively from the Python console, as the examples do, the desired file is created properly only when the code is entered in parts. That is, I can paste the code up to the first `output.tell()`, then copy & paste the remaining code (the image capture) into the console and have success. This tells me I have the code to create the image file; why does it not work from a Python file?
I have checked Python versions in both cases is the same (3.7.3) and use a Python virtual environment.
Thanks in advance for any input.

Edit: The second part of the code is the last 5 lines

 camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = True
 camera.outputs[2].params[mmal.MMAL_PARAMETER_CAPTURE] = False
 output.tell()
 camera.outputs[2].disable()
 output.close()

I had tried a 1 second delay between the two parts (in the .py file); still image.data file of 0 bytes.