class Pry::InputLock

def interruptible_region

def interruptible_region
  enter_interruptible_region
  # XXX Note that there is a chance that we get the interrupt right after
  # the readline call succeeded, but we'll never know, and we will retry the
  # call, discarding that piece of input.
  yield
rescue Interrupt
  # We were asked to back off. The one requesting the interrupt will be
  # waiting on the conditional for the interruptible flag to change to false.
  # Note that there can be some inefficiency, as we could immediately
  # succeed in enter_interruptible_region(), even before the one requesting
  # the ownership has the chance to register itself as an owner.
  # To mitigate the issue, we sleep a little bit.
  leave_interruptible_region
  sleep 0.01
  retry
ensure
  leave_interruptible_region
end