Serial port disconnects, when programmable power socket is activated

There are a few tutorials on the forum for using python in combination with Arduino. One is in "Introductory Tutorials" and one in this section of the forum (Demo of PC-Arduino comms using Python). Study both of them.