Skip to content

Commit

Permalink
Rely on subprocess.DEVNULL, available since Python 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 24, 2024
1 parent 7ec0520 commit dbbd380
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jaraco/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
from jaraco.functools import retry
from jaraco.services import paths

DEV_NULL = open(os.path.devnull, 'r+', encoding='utf-8')

log = logging.getLogger('jaraco.postgres')


Expand Down Expand Up @@ -396,7 +394,7 @@ def initdb(self, quiet=True, locale='en_US.UTF-8', encoding=None):
self.base_pathname = tempfile.mkdtemp()
if not os.path.isdir(self.base_pathname):
os.mkdir(self.base_pathname)
stdout = DEV_NULL if quiet else None
stdout = subprocess.DEVNULL if quiet else None
# The database superuser needs no password at this point(!).
arguments = [
'--auth=trust',
Expand Down Expand Up @@ -477,7 +475,7 @@ def _is_running(self, tries=10):
votes = 0
while abs(votes) < tries:
time.sleep(0.1)
running = subprocess.call(cmd, stdout=DEV_NULL) == 0
running = subprocess.call(cmd, stdout=subprocess.DEVNULL) == 0
if running and votes >= 0:
votes += 1
elif not running and votes <= 0:
Expand Down Expand Up @@ -521,7 +519,10 @@ def ready(self):
it occasionally takes 5-10 seconds for postgresql to start listening.
"""
subprocess.check_call(
self._psql_cmd(), stdin=DEV_NULL, stdout=DEV_NULL, stderr=DEV_NULL
self._psql_cmd(),
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)

@property
Expand Down

0 comments on commit dbbd380

Please sign in to comment.