Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid persistent handle on IOLoop instance #102

Merged
merged 1 commit into from
May 13, 2021
Merged
Changes from all 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
15 changes: 9 additions & 6 deletions terminado/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def byte_code(x): return x
import os
import signal
import codecs
import warnings

try:
from ptyprocess import PtyProcessUnicode
Expand Down Expand Up @@ -156,10 +157,11 @@ def __init__(self, shell_command, server_url="", term_settings={},
self.ptys_by_fd = {}

if ioloop is not None:
self.ioloop = ioloop
else:
import tornado.ioloop
self.ioloop = tornado.ioloop.IOLoop.instance()
warnings.warn(
f"Setting {self.__class__.__name__}.ioloop is deprecated and ignored",
DeprecationWarning,
stacklevel=2,
)

def make_term_env(self, height=25, width=80, winheight=0, winwidth=0, **kwargs):
"""Build the environment variables for the process in the terminal."""
Expand Down Expand Up @@ -194,7 +196,8 @@ def start_reading(self, ptywclients):
"""Connect a terminal to the tornado event loop to read data from it."""
fd = ptywclients.ptyproc.fd
self.ptys_by_fd[fd] = ptywclients
self.ioloop.add_handler(fd, self.pty_read, self.ioloop.READ)
loop = IOLoop.current()
loop.add_handler(fd, self.pty_read, loop.READ)

def on_eof(self, ptywclients):
"""Called when the pty has closed.
Expand All @@ -203,7 +206,7 @@ def on_eof(self, ptywclients):
fd = ptywclients.ptyproc.fd
self.log.info("EOF on FD %d; stopping reading", fd)
del self.ptys_by_fd[fd]
self.ioloop.remove_handler(fd)
IOLoop.current().remove_handler(fd)

# This closes the fd, and should result in the process being reaped.
ptywclients.ptyproc.close()
Expand Down