Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created March 3, 2017 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/585bfd8f93e6c18a22284a2a8b44bb0a to your computer and use it in GitHub Desktop.
Save peterbe/585bfd8f93e6c18a22284a2a8b44bb0a to your computer and use it in GitHub Desktop.
import threading
import psycopg2
def updater():
connection = psycopg2.connect('dbname=crontabber_exampleapp')
cursor = connection.cursor()
cursor.execute("""
SELECT ongoing FROM crontabber WHERE app_name = 'bar'
FOR UPDATE NOWAIT
""")
cursor.execute("""
UPDATE crontabber SET ongoing = now() WHERE app_name = 'bar'
""")
print("JOB CAN START!")
connection.commit()
# Use threads to simulate starting two connections virtually
# simultaneously.
threads = [
threading.Thread(target=updater),
threading.Thread(target=updater),
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment