title: Script runs on windows startup but exits immediately even with forever loop
body: <p>I am trying to make my python script to start on windows boot. I have managed to start with registry, shortcut in startup folder and taskscheduler. However, windows stops the script immediately. This does not persist if I use the same start command on CMD or double clicking the shortcut. Only when trying to get it start automatically. </p>
  
  <p>One more problem i have noticed, that when i run script with .pyw extension nothing happens. But it works if i use pythonw in CMD. Not sure if that has to do anything with the problem.</p>
  
  <p>I am using Windows 10, python 3.7 and this is my code:</p>
  
  <pre><code>from serial import Serial
  from time import sleep
  
  ser = Serial('COM7', 9600)
  while True:
      ser.write(b'1')
      sleep(1)
  </code></pre>
  
  <p>Launch script:</p>
  
  <pre><code>pythonw "%UserProfile%\PyCharm\hearthbeat\hearthbeat.pyw"
  </code></pre>