import gevent
import gevent.greenlet
import json

from gevent.pywsgi import WSGIServer
from gevent.server import StreamServer
from tendrl.commons.event import Event
from tendrl.commons.message import ExceptionMessage
from tendrl.monitoring_integration.alert.handlers import AlertHandlerManager

HOST = "127.0.0.1"
PORT = 8789


class WebhookReceiver(gevent.greenlet.Greenlet):
    def __init__(self):
        super(WebhookReceiver, self).__init__()
        self.server = WSGIServer(
            (HOST, PORT),
            self._application
        )
        self.alert_handler = AlertHandlerManager()

    def _application(self, env, start_response):
        try:
            if env['PATH_INFO'] != '/grafana_callback':
                start_response(
                    '404 Not Found',
                    [('Content-Type', 'text/html')]
                )
                response = [b'<h1>Alert Not Found</h1>']
            else:
                data = env['wsgi.input'].read()
                data = json.loads(data)
                self.alert_handler.handle_alert(
                    data["ruleId"]
                )
                start_response(
                    '200 OK',
                    [('Content-Type', 'text/html')]
                )
                response = [b'<h1>Alert Received</h1>']
        except (IOError, AssertionError) as ex:
            Event(
                ExceptionMessage(
                    priority="error",
                    publisher=NS.publisher_id,
                    payload={
                        "message": "Unable to read alert from socket",
                        "exception": ex
                    }
                )
            )
            response = [b'<h1>Error in reading alert from socket</h1>']

        return response

    def _run(self):
        try:
            self.server.serve_forever()
        except (TypeError,
                ValueError) as ex:
            Event(
                ExceptionMessage(
                    priority="error",
                    publisher=NS.publisher_id,
                    payload={
                        "message": "Unable to start wehook receiver",
                        "exception": ex
                    }
                )
            )

    def stop(self):
        pass

@@ -4,22 +4,20 @@
 ort 
-gevent
+json
 %0Aimport 
 geve
@@ -16,100 +16,48 @@
 ort 
-gevent.greenlet%0Aimport json%0A%0Afrom gevent.pywsgi import WSGIServer%0Afrom gevent
+threading%0A%0Afrom werkzeug
 .serv
-er
+ing
  import 
 Stre
@@ -56,20 +56,19 @@
 ort 
-StreamServer
+run_simple%0A
 %0Afro
@@ -292,32 +292,24 @@
 ver(
-gevent.greenlet.Greenlet
+threading.Thread
 ):%0A 
@@ -396,94 +396,21 @@
 elf.
-server = WSGIServer(%0A            (HOST, PORT),%0A            self._application%0A        )
+daemon = True
 %0A   
@@ -1655,17 +1655,16 @@
     def 
-_
 run(self
@@ -1695,34 +1695,63 @@
     
-self.server.serve_forever(
+run_simple(HOST, PORT, self._application, threaded=True
 )%0A  

Update webhook_receiver.py