Skip to content

Commit bdafcec

Browse files
committed
ensure unix_console.{prepare,restore} maintain state properly for when signal fails (ie in a thread), test
1 parent 7527783 commit bdafcec

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pyrepl/unix_console.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ def restore(self):
393393

394394
if hasattr(self, 'old_sigwinch'):
395395
signal.signal(signal.SIGWINCH, self.old_sigwinch)
396+
del self.old_sigwinch
396397

397398
def __sigwinch(self, signum, frame):
398399
self.height, self.width = self.getheightwidth()

testing/test_bugs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,29 @@ def test_cmd_instantiation_crash():
4444
('accept', [''])
4545
]
4646
read_spec(spec, HistoricalTestReader)
47+
48+
49+
def test_signal_failure(monkeypatch):
50+
import os
51+
import pty
52+
import signal
53+
from pyrepl.unix_console import UnixConsole
54+
55+
def failing_signal(a, b):
56+
raise ValueError
57+
58+
def really_failing_signal(a, b):
59+
raise AssertionError
60+
61+
mfd, sfd = pty.openpty()
62+
try:
63+
c = UnixConsole(sfd, sfd)
64+
c.prepare()
65+
c.restore()
66+
monkeypatch.setattr(signal, 'signal', failing_signal)
67+
c.prepare()
68+
monkeypatch.setattr(signal, 'signal', really_failing_signal)
69+
c.restore()
70+
finally:
71+
os.close(mfd)
72+
os.close(sfd)

0 commit comments

Comments
 (0)