title: PySide2 raises error, "QPaintDevice: Cannot destroy paint device that is being painted"
body: <p>I'm trying to paint something on a <code>QPixmap</code>, but it throws an error during cleanup.</p>
  
  <pre><code>from PySide2.QtGui import QPixmap, QPainter
  from PySide2.QtWidgets import QApplication
  
  app = QApplication()
  width = 200
  height = 100
  pixmap = QPixmap(width, height)
  painter = QPainter(pixmap)
  painter.drawLine(0, 0, 100, 100)
  print('Done.')
  </code></pre>
  
  <p>When I run that, I see the 'Done' message, and then an error.</p>
  
  <pre><code>Done.
  QPaintDevice: Cannot destroy paint device that is being painted
  
  Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
  </code></pre>
  
  <p>I've seen some similar questions with the same error, but it's not clear what's causing the error or how to avoid it.</p>