@@ -52,10 +52,10 @@ def __init__(self, client, database: str, session_type: SessionType, options=Gra
5252
5353 self ._session_id = self ._grpc_stub .session_open (open_req ).session_id
5454 self ._is_open = True
55- self ._scheduler .enter (delay = self ._PULSE_FREQUENCY_SECONDS , priority = 1 , action = self ._transmit_pulse , argument = ())
55+ self ._pulse = self . _scheduler .enter (delay = self ._PULSE_FREQUENCY_SECONDS , priority = 1 , action = self ._transmit_pulse , argument = ())
5656 # TODO: This thread blocks the process from closing. We should try cancelling the scheduled task when the
5757 # session closes. If that doesn't work, we need some other way of getting the thread to exit.
58- Thread (target = self ._scheduler .run ).start ()
58+ Thread (target = self ._scheduler .run , daemon = True ).start ()
5959
6060 def transaction (self , transaction_type : TransactionType , options = GraknOptions ()):
6161 return Transaction (self ._channel , self ._session_id , transaction_type , options )
@@ -67,6 +67,8 @@ def is_open(self): return self._is_open
6767 def close (self ):
6868 if self ._is_open :
6969 self ._is_open = False
70+ self ._scheduler .cancel (self ._pulse )
71+ self ._scheduler .empty ()
7072 req = session_proto .Session .Close .Req ()
7173 req .session_id = self ._session_id
7274 self ._grpc_stub .session_close (req )
@@ -80,8 +82,8 @@ def _transmit_pulse(self):
8082 pulse_req .session_id = self ._session_id
8183 res = self ._grpc_stub .session_pulse (pulse_req )
8284 if res .alive :
83- self ._scheduler .enter (delay = self ._PULSE_FREQUENCY_SECONDS , priority = 1 , action = self ._transmit_pulse , argument = ())
84- Thread (target = self ._scheduler .run ).start ()
85+ self ._pulse = self . _scheduler .enter (delay = self ._PULSE_FREQUENCY_SECONDS , priority = 1 , action = self ._transmit_pulse , argument = ())
86+ Thread (target = self ._scheduler .run , daemon = True ).start ()
8587
8688 def __enter__ (self ):
8789 return self
0 commit comments