When you initialize COM port (in Python) Arduino will restart. So, I suggest you try increasing time from 1ms to 1s by changing your code to:
import serial
import time
arduino2 = serial.Serial(port='COM12', baudrate=9600, timeout=.1)
time.sleep(1000)
arduino2.write(str.encode("u"))
This additional time should be enough for Arduino Nano to restart and respond to serial communication.