Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Catch FileNotFoundError exception#74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletionstestgres/enums.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
from enum import Enum, IntEnum
from six import iteritems
from psutil import NoSuchProcess


class XLogMethod(Enum):
Expand DownExpand Up@@ -68,11 +69,15 @@ def from_process(process):
],
} # yapf: disable

try:
cmdline = ''.join(process.cmdline())
except (FileNotFoundError, ProcessLookupError, NoSuchProcess):
return ProcessType.Unknown

# we deliberately cut special words and spaces
cmdline = ''.join(process.cmdline()) \
.replace('postgres:', '', 1) \
.replace('bgworker:', '', 1) \
.replace(' ', '')
cmdline = cmdline.replace('postgres:', '', 1) \
.replace('bgworker:', '', 1) \
.replace(' ', '')

for ptype in ProcessType:
if cmdline.startswith(ptype.value.replace(' ', '')):
Expand Down
14 changes: 14 additions & 0 deletionstests/test_simple.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
import time
import six
import unittest
import psutil

import logging.config

Expand DownExpand Up@@ -48,6 +49,7 @@
# NOTE: those are ugly imports
from testgres import bound_ports
from testgres.utils import PgVer
from testgres.node import ProcessProxy


def pg_version_ge(version):
Expand DownExpand Up@@ -965,6 +967,18 @@ def test_child_pids(self):
with self.assertRaises(TestgresException):
replica.source_walsender

def test_child_process_dies(self):
# test for FileNotFound exception during child_processes() function
with subprocess.Popen(["sleep", "60"]) as process:
self.assertEqual(process.poll(), None)
# collect list of processes currently running
children = psutil.Process(os.getpid()).children()
# kill a process, so received children dictionary becomes invalid
process.kill()
process.wait()
# try to handle children list -- missing processes will have ptype "ProcessType.Unknown"
[ProcessProxy(p) for p in children]


if __name__ == '__main__':
if os.environ.get('ALT_CONFIG'):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp