Reset board after doing "pio run --target upload" using extra scripts

Hello Folks,

I need to reset nano BLE sense board after running “pio run --target upload”

I am following the thread -

Tried to do something like below in reset.py (kept in same folder as platform.ini) -

Import(“env”)
import os
from platformio.builder.tools.pioupload import AutodetectUploadPort
from platformio.builder.tools.pioupload import TouchSerialPort

platform = env.PioPlatform()
print(“Doing AutodetectUploadPort”)
AutodetectUploadPort(env)
upload_port = env.subst(‘$UPLOAD_PORT’)
TouchSerialPort(env, upload_port, 1200)
print(“Doing TouchSerialPort”)

My platform.ini has “extra_scripts = post:reset.py”

But above code doesn’t seem to cause the reset. Am I missing something? I am monitoring the reset on a separate terminal running “pio device monitor”. This is Ubuntu 18.

I am newbie in pio and python so please bear with me. Please guide to some document or example code.
Thanks!