P
P
Pretendi2015-04-27 23:37:18
Python
Pretendi, 2015-04-27 23:37:18

How to refer to RequestHandlerClass in BaseHTTPServer?

try:
  server = http.server.HTTPServer(("", 8080), Handler_http)
  print ("started httpserver...")
  server.serve_forever()
except KeyboardInterrupt:
  print ("^C received, shutting down server")
  server.socket.close()

How to call the function described in Handler_http? For example, so that it works when the server is closed
. Why does the Handler_http class call __del__ when processing each request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pretendi, 2015-04-28
@Pretendi

Nothing smarter

class Handler_http(BaseHTTPRequestHandler):
  dataset = {}
  try:
    f = open('data.pickle', 'rb')
    dataset = pickle.load(f)
  except:
    pass
  def save_data(self):
    with open('data.pickle', 'wb') as f:
      pickle.dump(Handler_http.dataset, f)
.
.

I think something is not right here, it's ugly. I didn’t find any other options, that when starting the server, to read the data, and to write it down when it stops, taking into account the fact that I change the data with queries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question