title: Handle connection close with python jsocket
body: <p>I am using a json socket server/client using the <a href="https://cpiekarski.com/2012/01/25/python-json-client-server-redux/" rel="nofollow noreferrer"><code>jsocket</code> python library.</a></p>
  <p>I made request to the server with a client that is open and close the connection each time.
  My server crashes after the first time the connection is closed. How can I maintain the server running?</p>
  <p>The server code:</p>
  <pre><code>import logging
  import random
  import sys
  import time
  
  import jsocket
  
  logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
  
  
  class DataloggerServer(jsocket.ServerFactoryThread):
      # This is an example factory thread, which the server factory will
      # instantiate for each new connection.
      def __init__(self):
          super(DataloggerServer, self).__init__()
          self.timeout = 2.0
  
  #    def isAlive(self):
  #        return True
  
      def _process_message(self, obj):
          # virtual method - Implementer must define protocol
          logging.debug(&quot;Recived object %s&quot;, obj)
          if obj != '':
              if obj['type'] == &quot;REQ_VAR_SAMPLE&quot;:
                  data = obj['data']
                  var_name = data[&quot;id&quot;]
                  logging.debug(&quot;Got variable name %s&quot;, var_name)
                  if var_name == 'EMERGENCY':
                      value = 0 if random.random() &lt; 0.75 else 1
                      logging.debug(&quot;variable value: %s&quot;, value)
                  elif var_name == &quot;RPM_SPINDLE&quot;:
                      value = 70 if random.random() &lt; 0.85 else 45
                  elif var_name == &quot;FEEDRATE_OVERRIDE&quot;:
                      value = 50 if random.random() &lt; 0.85 else 75
                  sample = {}
                  timestamp = int(time.time()*1000)
                  sample['timestamp'] = timestamp
                  sample['value'] = value
                  logging.debug(&quot;created sample %s&quot;, sample)
              else:
                  logging.info(obj)
                  sample = {}
          data = {'sample': sample}
          res_obj = {
                  &quot;type&quot;: &quot;RESP_SAMPLE&quot;,
                  &quot;data&quot;: data
          }
          logging.debug(&quot;Response object: %s&quot;, res_obj)
          self.send_obj(res_obj)
  
  
  if __name__ == '__main__':
      server = jsocket.ServerFactory(DataloggerServer, address=&quot;0.0.0.0&quot;, port=12340)
      server.timeout = 2.0
      server.start()
      print(&quot;Datalogger server started&quot;)
  </code></pre>
  <p>The client, basically, does this:</p>
  <pre><code>    monitor_client.open()
      value_timestamp, value = monitor_client.get_var_sample(variable_name)
      monitor_client.close()
  </code></pre>
  <p>where <code>monitor_client</code> has a  <code>jsocket.JsonClient</code> attribute object. Opens connection, does some request and closes the connection. When the client closes I got the following error at the server side:</p>
  <pre><code>DEBUG:root:Response object: {'type': 'RESP_SAMPLE', 'data': {'sample': {'timestamp': 1630055461803, 'value': 0}}}
    File &quot;/home/zia/.local/share/virtualenvs/vixion-edge-horus-notifier-sNtaDgls/lib/python3.9/site-packages/jsocket/tserver.py&quot;, line 162, in run
      self._purge_threads()
    File &quot;/home/zia/.local/share/virtualenvs/vixion-edge-horus-notifier-sNtaDgls/lib/python3.9/site-packages/jsocket/tserver.py&quot;, line 189, in _purge_threads
      if not t.isAlive():
  AttributeError: 'DataloggerServer' object has no attribute 'isAlive'
  INFO:jsocket.tserver:client connection broken, closing socket
  DEBUG:jsocket:closing the connection socket
  DEBUG:jsocket:closing main socket
  </code></pre>
  <p>(The first line is correct debug info).</p>