0

I have a large PostgreSQL database which takes days or weeks to run our business queries. I am developing a Python front-end for users to trigger these queries. I would like to know if it is possible to detach the python process from the queries it triggers in PG so the front end can be closed, leaving the queries to run quietly in the DB?

James N
  • 603
  • 3
  • 8
  • 18
  • Why not just background or daemonize the process? – user2864740 Feb 11 '15 at 21:22
  • You're right, I just found this answer: http://stackoverflow.com/questions/5772873/python-spawn-off-a-child-subprocess-detach-and-exit. I can't suggest my own answer yet because I haven't tested it – James N Feb 11 '15 at 21:24

1 Answers1

0

It turns out this was trivial, from this answer to a similar question. I didn't mention I was using Windows, which makes a difference.

import subprocess
cmd = ['psql', '-d', 'test', '-U', 'postgres', '-f', 'test_points.pgsql']
subprocess.Popen(cmd)  # will run in the background if the output is not used in the rest of the script
Community
  • 1
  • 1
James N
  • 603
  • 3
  • 8
  • 18