subprocess.call(['pmset', '-g', 'assertions'])
time.sleep(5)
AssertionRelease(framework, a_id)
print("""

Releasing power assertion: id %s

""" % a_id)
subprocess.call(['pmset', '-g', 'assertions'])
if __name__ == '__main__':
    main()
How to check whether screen is off in Mac/Python?