Skip to content

Commit

Permalink
Merge pull request #469 from ccordoba12/py2-compat
Browse files Browse the repository at this point in the history
PR: Restore compatibility with Python 2
  • Loading branch information
ccordoba12 committed Oct 9, 2023
2 parents 9687928 + 6ca7b7a commit 53c95fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions spyder_kernels/comms/frontendcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from spyder_kernels.py3compat import TimeoutError, PY2


if PY2:
import thread


def get_free_port():
"""Find a free port on the local machine."""
sock = socket.socket()
Expand Down Expand Up @@ -264,7 +268,7 @@ def _remote_callback(self, call_name, call_args, call_kwargs):
current_stderr = sys.stderr
saved_stdout_write = current_stdout.write
saved_stderr_write = current_stderr.write
thread_id = threading.get_ident()
thread_id = thread.get_ident() if PY2 else threading.get_ident()
current_stdout.write = WriteWrapper(
saved_stdout_write, call_name, thread_id)
current_stderr.write = WriteWrapper(
Expand Down Expand Up @@ -300,7 +304,8 @@ def is_benign_message(self, message):

def __call__(self, string):
"""Print warning once."""
if self._thread_id != threading.get_ident():
thread_id = thread.get_ident() if PY2 else threading.get_ident()
if self._thread_id != thread_id:
return self._write(string)

if not self.is_benign_message(string):
Expand Down
3 changes: 2 additions & 1 deletion spyder_kernels/console/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def kernel_config():

# Disable the new mechanism to capture and forward low-level output
# in IPykernel 6. For that we have Wurlitzer.
spy_cfg.IPKernelApp.capture_fd_output = False
if not PY2:
spy_cfg.IPKernelApp.capture_fd_output = False

# Merge IPython and Spyder configs. Spyder prefs will have prevalence
# over IPython ones
Expand Down

0 comments on commit 53c95fe

Please sign in to comment.