@@ -884,7 +884,12 @@ def __init__(self, *args, **kwargs):
884884 super ().__init__ (* args , ** kwargs )
885885 self .last_usage = self .loop .time ()
886886
887- async def _initialize_socket (self ):
887+ async def _initialize (self ):
888+ self .last_event_id = 0
889+ self ._autocommit = False
890+ self ._transaction = None
891+ self ._cursors = {}
892+
888893 self .sock = AsyncSocketStream (self .hostname , self .port , self .loop , self .timeout , self .cloexec )
889894
890895 self ._op_connect (self .auth_plugin_name , self .wire_crypt )
@@ -897,7 +902,7 @@ async def _initialize_socket(self):
897902 self ._op_attach (self .timezone )
898903 (h , oid , buf ) = await self ._async_op_response ()
899904 self .db_handle = h
900- DEBUG_OUTPUT ("AsyncConnection::_initialize_socket ()" , self .db_handle )
905+ DEBUG_OUTPUT ("AsyncConnection::_initialize ()" , self .db_handle )
901906
902907 async def __aenter__ (self ):
903908 return self
@@ -910,6 +915,10 @@ async def __aexit__(self, exc, value, traceback):
910915 await self .commit ()
911916 await self .close ()
912917
918+ async def reconnect (self ):
919+ self .close ()
920+ await self ._initialize ()
921+
913922 async def set_autocommit (self , is_autocommit ):
914923 if self ._autocommit != is_autocommit and self ._transaction is not None :
915924 await self .rollback ()
0 commit comments