QWidget Close Event in PySide

import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QMessageBox)

class MainWindow(QWidget):
  def __init__(self):
    super().__init__()

  def closeEvent(self, event):
    reply = QMessageBox.question(self, 'Window Close', 'Are you sure you want to close the window?',
        QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

    if reply == QMessageBox.Yes:
      event.accept()
      print('Window closed')
    else:
      event.ignore()

if __name__ == '__main__':
  app = QApplication(sys.argv)

  demo = MainWindow()
  demo.show()

  sys.exit(app.exec_())

References
https://learndataanalysis.org/example-of-how-to-use-the-qwidget-close-event-pyqt5-tutorial/

SQlite WAL-mode in python

Reader

import sqlite3
from time import sleep
conn = sqlite3.connect('example.db', isolation_level=None)

c = conn.cursor()
while True:
    c.execute("SELECT * FROM statistics")
    try:
        print '**'
        print c.fetchone()
    except:
        pass
    sleep(3)

Writer

import sqlite3
from time import sleep
import os

if os.path.exists('example.db'):
    os.remove('example.db')

conn = sqlite3.connect('example.db', isolation_level=None)
c = conn.cursor()
c.execute('PRAGMA journal_mode=wal')
print c.fetchone()
c.execute("CREATE TABLE statistics (stat1 real, stat2 real)")

stat1 = 0
stat2 = 0.0
while True:
    stat1 += 1
    stat2 += 0.1
    cmd = "INSERT INTO statistics VALUES (%d,%f)" % (stat1, stat2)
    print cmd
    c.execute(cmd)
    #conn.commit()
    c.execute("PRAGMA wal_checkpoint=FULL")
    sleep(0.25)

References
https://stackoverflow.com/questions/30821179/sqlite-wal-mode-in-python-concurrency-with-one-writer-and-one-reader
https://sqlite.org/wal.html