title: pygame.init() fails when run with systemd
body: <p>I'm trying to run a python pygame script with systemd and for some reason the script just exits without an error.
  This is on a Raspberry Pi with Raspian "Jessie lite".</p>
  
  <p><strong>If I run the script manually with "sudo python myscript.py" it works fine.</strong></p>
  
  <p>sudo systemctl status myscript.service reports:</p>
  
  <pre><code>* myscript.service - Python Script
  Loaded: loaded    /etc/systemd/system/myscript.service; enabled)    Active: inactive (dead) since Mon 2016-08-29 04:33:19 UTC; 1s ago
  Process: 3275&gt; ExecStart=/usr/bin/python /home/pi/myscript.py (code=killed, signal=HUP)
  Main PID: 3275 (code=killed, signal=HUP)
  </code></pre>
  
  <p>If I start the service manually with sudo systemctl start myscript.service the same thing happens.</p>
  
  <p>I've stripped down my script to just the pygame.init() call. This is where it exits.</p>
  
  <p>If I try to initialize the modules manually then "cdrom", "joystick", "threads", and "font" initialize normally but a call to display.init() causes the program to exit. There is no exception raised.</p>
  
  <p>The only resource I could find online is <a href="https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/AZcdQfQDMVY" rel="nofollow">this guy</a>. It seems he ran into the exact same thing I'm seeing.
  I've tried strace and if I wait long enough (2 minutes), it will work!
  Obviously I can't run with strace all the time. I think it slows down the execution of the initialization to somehow allow it to work.</p>
  
  <p>EDIT:
  So the issue appears to be systemd sending a SIGHUP. If this is unhandled in Python the default action is to exit. A quick fix is the catch SIGHUP:</p>
  
  <pre><code>import signal
  def handler(signum, frame):
      pass
  
  try:
      signal.signal(signal.SIGHUP, handler)
  except AttributeError:
      # Windows compatibility
      pass
  </code></pre>
  
  <p>So many burning questions. Why does systemd do this? Why does strace fix the issue? Why do some Python scripts get SIGHUP while others don't?</p>