Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import asyncio
  2. import aiopg
  3. import primesieve
  4.  
  5. async def put_prime(loop):
  6. dsn = 'dbname=mydb user=postgres password=dbpassword host=127.0.0.1'
  7. async with aiopg.create_pool(dsn) as pool, pool.acquire() as conn, conn.cursor() as cur:
  8. it = primesieve.Iterator()
  9. while True:
  10. await cur.execute("NOTIFY prime, %s", [str(it.next_prime())])
  11. await asyncio.sleep(5)
  12.  
  13. if __name__ == '__main__':
  14. loop = asyncio.get_event_loop()
  15. loop.run_until_complete(put_prime(loop))
  16. loop.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement