See 'machine.pin.hold()' :
"Get or set the pin hold. You can apply a hold to a pin by passing True (or clear it by passing False). When a pin is held, its value cannot be changed by using Pin.value() or Pin.toggle() until the hold is released. This Can be used to retain the pin state through a core reset and system reset triggered by watchdog time-out or Deep-sleep events. Only pins in the RTC power domain can retain their value through deep sleep or reset.
These are: P2, P3, P4, P6, P8, P9, P10, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23"