##// END OF EJS Templates
Backport PR #2717: One liner to fix debugger printing stack traces when lines of context are larger than source....
Backport PR #2717: One liner to fix debugger printing stack traces when lines of context are larger than source. Correctly print stack traces when context is larger than lines of source. To test: ``` In [6]: def bar(): ...: return 20 ...: ``` Before: ``` In [7]: ipdb.runcall(bar) <ipython-input-6-d0ed3bd5e16c>(2)bar() 0 return 20 ``` And here's after: ``` In [6]: ipdb.runcall(bar) <ipython-input-5-d0ed3bd5e16c>(2)bar() 1 def bar(): ----> 2 return 20 ``` Replaces gh-2697. (Adds a test.)

File last commit:

r5390:c82649ea
r9850:72c7e714
Show More
heartbeat.py
48 lines | 1.6 KiB | text/x-python | PythonLexer
"""The client and server for a basic ping-pong style heartbeat.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import socket
import sys
from threading import Thread
import zmq
from IPython.utils.localinterfaces import LOCALHOST
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
def __init__(self, context, addr=(LOCALHOST, 0)):
Thread.__init__(self)
self.context = context
self.ip, self.port = addr
if self.port == 0:
s = socket.socket()
# '*' means all interfaces to 0MQ, which is '' to socket.socket
s.bind(('' if self.ip == '*' else self.ip, 0))
self.port = s.getsockname()[1]
s.close()
self.addr = (self.ip, self.port)
self.daemon = True
def run(self):
self.socket = self.context.socket(zmq.REP)
self.socket.bind('tcp://%s:%i' % self.addr)
zmq.device(zmq.FORWARDER, self.socket, self.socket)