title: Python+pika, how do I force closure of AMQP channel and AMQP connection
body: <p>I would like to consume one message (or wait till some 2 seconds have elapsed) and then close the AMQP connection and continue with other processing.
  So far I am stuck on closing the channel and connection.
  The code hangs on channel.close() producing the output below generated when I run python3 -m trace --trace.</p>
  <p>Is there an example on how to do this?</p>
  <p>The code output before generated by the use of -m trace --trace shows the lines of code being executed (from pika python scripts) for the channel.close() instruction in my script.</p>
  <p>It seems there are some endless loops being executed here, is there a way to avoid or forcefully exit from these loops as I simply would like to close the channel and then the connection so that execution may reach the end of my function.</p>
  <p>In short is there a way to close a connection without terminating the entire script so that subsequent lines of code can be executed?</p>
  <pre><code>select_connection.py(688):         if delay is None:
  select_connection.py(689):             delay = self._MAX_POLL_TIMEOUT
  select_connection.py(693):         return delay * self.POLL_TIMEOUT_MULT
  select_connection.py(1185):                 break
  select_connection.py(1192):         fd_event_map = collections.defaultdict(int)
  select_connection.py(1193):         for fileno, event in events:
  select_connection.py(1203):         self._dispatch_fd_events(fd_event_map)
   --- modulename: select_connection, funcname: _dispatch_fd_events
  select_connection.py(891):         self._processing_fd_event_map.clear()
  select_connection.py(893):         self._processing_fd_event_map = fd_event_map
  select_connection.py(895):         for fileno in pika.compat.dictkeys(fd_event_map):
   --- modulename: compat, funcname: dictkeys
  compat.py(73):         return list(dct.keys())
  blocking_connection.py(515):             self._impl.ioloop.process_timeouts()
   --- modulename: base_connection, funcname: ioloop
  base_connection.py(198):         return self._nbio.get_native_ioloop()
   --- modulename: selector_ioloop_adapter, funcname: get_native_ioloop
  selector_ioloop_adapter.py(191):         return self._loop
   --- modulename: select_connection, funcname: process_timeouts
  select_connection.py(492):         for _ in pika.compat.xrange(len(self._callbacks)):
  select_connection.py(497):         self._timer.process_timeouts()
   --- modulename: select_connection, funcname: process_timeouts
  select_connection.py(311):         if self._timeout_heap:
  blocking_connection.py(513):         while not is_done():
   --- modulename: blocking_connection, funcname: &lt;lambda&gt;
  blocking_connection.py(507):                    self._closed_result.ready or
   --- modulename: blocking_connection, funcname: ready
  blocking_connection.py(94):         return self._ready
  blocking_connection.py(508):                    ((not self._impl._transport or
  blocking_connection.py(509):                      self._impl._get_write_buffer_size() == 0) and
   --- modulename: select_connection, funcname: _get_write_buffer_size
  select_connection.py(143):         return self._transport.get_write_buffer_size()
   --- modulename: io_services_utils, funcname: get_write_buffer_size
  io_services_utils.py(748):         return self._tx_buffered_byte_count
  blocking_connection.py(510):                     (not waiters or any(ready() for ready in waiters))))
   --- modulename: blocking_connection, funcname: &lt;genexpr&gt;
  blocking_connection.py(510):                     (not waiters or any(ready() for ready in waiters))))
   --- modulename: blocking_connection, funcname: &lt;lambda&gt;
  blocking_connection.py(820):             common_terminator = lambda: bool(dispatch_acquired and
  blocking_connection.py(821):                                              (self._channels_pending_dispatch or
  blocking_connection.py(822):                                               self._ready_events))
   --- modulename: blocking_connection, funcname: &lt;genexpr&gt;
  blocking_connection.py(510):                     (not waiters or any(ready() for ready in waiters))))
  blocking_connection.py(514):             self._impl.ioloop.poll()
   --- modulename: base_connection, funcname: ioloop
  base_connection.py(198):         return self._nbio.get_native_ioloop()
   --- modulename: selector_ioloop_adapter, funcname: get_native_ioloop
  selector_ioloop_adapter.py(191):         return self._loop
  </code></pre>