cancel rendering

hi

is there a way to stop a render programmatically ?

the following code starts the render

bpy.ops.render.render(write_still=True)

but i would like to stop the rendering after x amount of time

so with this i am actually interested in getting a ‘partially rendered’ image

actually hitting the ‘esc’ key stops the rendering
and there is also this button ‘Stop this job’ that stops the rendering

do we have access through python to these methods of cancelling a rendering ?

thanks for any help