Skip to content

Commit

Permalink
New distribution [0.3.2]
Browse files Browse the repository at this point in the history
 - revised _kill to avoid possible orphan
  • Loading branch information
JarryShaw committed Jan 7, 2019
1 parent a4f7191 commit 3bb44f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.3.2

> Release date: 2019-01-07
  Kill child process (and its children) in a graceful way (to avoid orphan).

## Version 0.3.1.post1

> Release date: 2019-01-05
Expand Down
19 changes: 15 additions & 4 deletions ptyng.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# Author: Steen Lumholt -- with additions by Guido.

import contextlib
import io
import os
import signal
import sys
import tty
import warnings
from select import select

try:
Expand Down Expand Up @@ -232,11 +234,20 @@ def _copy(pid, master_fd, master_read=_read, stdin_read=_read):
_writen(master_fd, data)


def _kill(pid, signal):
def _kill(pid, signal, master_read):
"""Kill a process with a signal."""
with contextlib.suppress(OSError):
for chld in _fetch_child(pid):
class FileObject(io.IOBase):
def write(self, data):
os.write(master_read, bytes(data, 'utf-8', 'replace'))

file = FileObject(master_read)
for chld in reversed(_fetch_child(pid)):
try:
os.kill(chld, signal)
except OSError as error:
message = ('failed to send signal to process %d '
'with error message: %s') % (chld, error)
warnings.showwarning(message, ResourceWarning, __file__, 246, file)


def spawn(argv, master_read=_read, stdin_read=_read, timeout=None, env=None):
Expand All @@ -251,7 +262,7 @@ def spawn(argv, master_read=_read, stdin_read=_read, timeout=None, env=None):
os.execvpe(argv[0], argv, env)

if timeout is not None:
timer = threading.Timer(timeout, _kill, args=(pid, signal.SIGKILL))
timer = threading.Timer(timeout, _kill, args=(pid, signal.SIGKILL, master_fd))
timer.start()

try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
raise

# version string
__version__ = '0.3.1.post1'
__version__ = '0.3.2'

# install requires
try:
Expand Down

0 comments on commit 3bb44f4

Please sign in to comment.