How to set exposure time using picamera2

The following code will capture a 640x480 PNG image into Exposure10ms.png, using a fixed exposure of 10ms:

#!/usr/bin/env python3
import time
import picamera2
import numpy as np

with picamera2.Picamera2() as camera:
    camera.set_controls({"ExposureTime": 1000, "AnalogueGain": 1.0})
    camera.start()
    camera.capture_file("Exposure1ms.png")
    camera.stop()

Note that it is important to run camera.start() aftercamera.set_controls().