tk0miya / testing.postgresql

Apache License 2.0
290 stars 46 forks source link

provide an option to start subprocesses in a new process group #27

Closed brianmaissy closed 1 year ago

brianmaissy commented 5 years ago

I have a script which uses testing.postgres to create a temporary database to test against. My script has a SIGINT handler which handles teardown logic, which I want to run before the database is terminated.

The problem is that when one presses CTRL+C in a terminal, the shell sends SIGINT to the entire process group, thereby killing the postgres process before my teardown logic can finish running.

The solution I propose is to expose a boolean parameter to the testing.postgresql.Postgresql() constructor, which if True, will cause start_new_session=True to be passed to the call to subprocess.Popen in common/database.py, which will cause python to run setsid() in the child process before running postgres.

I'd be happy to open a PR if something along these lines sounds good to you.

brianmaissy commented 5 years ago

@tk0miya what do you think?

brianmaissy commented 5 years ago

In case anyone else is having the same problem, as a temporary workaround I monkeypatched subprocess.Popen while calling the testing.postgresql.Postgresql() constructor

brianmaissy commented 1 year ago

Personally this is no longer relevant for me, so in the spirit of Closember I am closing. @huytran1ibm or anyone else, feel free to comment if you still want this.