# Buggy code
def _start_polling(
    self,
    poll_interval,
    timeout,
    read_latency,
    bootstrap_retries,
    clean,
    allowed_updates,
):  # pragma: no cover
    # Thread target of thread 'updater'. Runs in background, pulls
    # updates from Telegram and inserts them in the update queue of the
    # Dispatcher.

    self.logger.debug("Updater thread started (polling)")

    self._bootstrap(
        bootstrap_retries, clean=clean, webhook_url="", allowed_updates=None
    )

    self.logger.debug("Bootstrap done")

    def polling_action_cb():
        updates = self.bot.get_updates(
            self.last_update_id,
            timeout=timeout,
            read_latency=read_latency,
            allowed_updates=allowed_updates,
        )

        if updates:
            if not self.running:
                self.logger.debug("Updates ignored and will be pulled again on restart")
            else:
                for update in updates:
                    self.update_queue.put(update)
                self.last_update_id = updates[-1].update_id + 1

        return True

    def polling_onerr_cb(exc):
        # Put the error into the update queue and let the Dispatcher
        # broadcast it
        self.update_queue.put(exc)

    self._network_loop_retry(
        polling_action_cb, polling_onerr_cb, "getting Updates", poll_interval
    )


# Traceback (NotImplementedError)
Exception in thread Bot:377489430:updater:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Program Files\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\telegram\ext\updater.py", line 216, in _thread_wrapper
target(*args, **kwargs)
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\telegram\ext\updater.py", line 452, in _start_webhook
self.httpd.serve_forever()
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\telegram\utils\webhookhandler.py", line 52, in serve_forever
self.http_server.listen(self.port, address=self.listen)
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\tornado\tcpserver.py", line 152, in listen
self.add_sockets(sockets)
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "C:\Users\User\.virtualenvs\sandbox38\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "C:\Program Files\Python38\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError

# Fixed code
def _start_polling(
    self,
    poll_interval,
    timeout,
    read_latency,
    bootstrap_retries,
    clean,
    allowed_updates,
    ready=None,
):  # pragma: no cover
    # Thread target of thread 'updater'. Runs in background, pulls
    # updates from Telegram and inserts them in the update queue of the
    # Dispatcher.

    self.logger.debug("Updater thread started (polling)")

    self._bootstrap(
        bootstrap_retries, clean=clean, webhook_url="", allowed_updates=None
    )

    self.logger.debug("Bootstrap done")

    def polling_action_cb():
        updates = self.bot.get_updates(
            self.last_update_id,
            timeout=timeout,
            read_latency=read_latency,
            allowed_updates=allowed_updates,
        )

        if updates:
            if not self.running:
                self.logger.debug("Updates ignored and will be pulled again on restart")
            else:
                for update in updates:
                    self.update_queue.put(update)
                self.last_update_id = updates[-1].update_id + 1

        return True

    def polling_onerr_cb(exc):
        # Put the error into the update queue and let the Dispatcher
        # broadcast it
        self.update_queue.put(exc)

    if ready is not None:
        ready.set()

    self._network_loop_retry(
        polling_action_cb, polling_onerr_cb, "getting Updates", poll_interval
    )