2525
2626class Connection (Stateful ):
2727 """AMQP Connection"""
28+ __slots__ = [
29+ 'heartbeat' , 'parameters' , '_channel0' , '_channels' , '_io'
30+ ]
2831
2932 def __init__ (self , hostname , username , password , port = 5672 , ** kwargs ):
3033 """
@@ -56,13 +59,12 @@ def __init__(self, hostname, username, password, port=5672, **kwargs):
5659 'ssl_options' : kwargs .get ('ssl_options' , {})
5760 }
5861 self ._validate_parameters ()
62+ self ._io = IO (self .parameters , exceptions = self ._exceptions ,
63+ on_read = self ._read_buffer )
5964 self ._channel0 = Channel0 (self )
65+ self ._channels = {}
6066 self .heartbeat = Heartbeat (self .parameters ['heartbeat' ],
6167 self ._channel0 .send_heartbeat )
62- self ._io = IO (self .parameters , on_read = self ._read_buffer ,
63- on_write = self .heartbeat .register_write )
64-
65- self ._channels = {}
6668 if not kwargs .get ('lazy' , False ):
6769 self .open ()
6870
@@ -119,7 +121,7 @@ def open(self):
119121 LOGGER .debug ('Connection Opening' )
120122 self .set_state (self .OPENING )
121123 self ._exceptions = []
122- self ._io .open (self . _exceptions )
124+ self ._io .open ()
123125 self ._send_handshake ()
124126 self ._wait_for_connection_to_open ()
125127 self .heartbeat .start (self ._exceptions )
@@ -183,6 +185,7 @@ def write_frame(self, channel_id, frame_out):
183185 :return:
184186 """
185187 frame_data = pamqp_frame .marshal (frame_out , channel_id )
188+ self .heartbeat .register_write ()
186189 self ._io .write_to_socket (frame_data )
187190
188191 def write_frames (self , channel_id , multiple_frames ):
@@ -195,6 +198,7 @@ def write_frames(self, channel_id, multiple_frames):
195198 frame_data = EMPTY_BUFFER
196199 for single_frame in multiple_frames :
197200 frame_data += pamqp_frame .marshal (single_frame , channel_id )
201+ self .heartbeat .register_write ()
198202 self ._io .write_to_socket (frame_data )
199203
200204 def _validate_parameters (self ):
0 commit comments