# Buggy code
def __init__(
    self,
    bot,
    update_queue,
    workers=4,
    exception_event=None,
    job_queue=None,
    persistence=None,
    use_context=False,
):
    self.bot = bot
    self.update_queue = update_queue
    self.job_queue = job_queue
    self.workers = workers
    self.use_context = use_context

    if not use_context:
        warnings.warn(
            "Old Handler API is deprecated - see https://git.io/fxJuV for details",
            TelegramDeprecationWarning,
            stacklevel=3,
        )

    self.user_data = defaultdict(dict)
    self.chat_data = defaultdict(dict)
    self.bot_data = {}
    if persistence:
        if not isinstance(persistence, BasePersistence):
            raise TypeError(
                "persistence should be based on telegram.ext.BasePersistence"
            )
        self.persistence = persistence
        if self.persistence.store_user_data:
            self.user_data = self.persistence.get_user_data()
            if not isinstance(self.user_data, defaultdict):
                raise ValueError("user_data must be of type defaultdict")
        if self.persistence.store_chat_data:
            self.chat_data = self.persistence.get_chat_data()
            if not isinstance(self.chat_data, defaultdict):
                raise ValueError("chat_data must be of type defaultdict")
        if self.persistence.store_bot_data:
            self.bot_data = self.persistence.get_bot_data()
            if not isinstance(self.bot_data, dict):
                raise ValueError("bot_data must be of type dict")
    else:
        self.persistence = None

    self.handlers = {}
    """Dict[:obj:`int`, List[:class:`telegram.ext.Handler`]]: Holds the handlers per group."""
    self.groups = []
    """List[:obj:`int`]: A list with all groups."""
    self.error_handlers = []
    """List[:obj:`callable`]: A list of errorHandlers."""

    self.running = False
    """:obj:`bool`: Indicates if this dispatcher is running."""
    self.__stop_event = Event()
    self.__exception_event = exception_event or Event()
    self.__async_queue = Queue()
    self.__async_threads = set()

    # For backward compatibility, we allow a "singleton" mode for the dispatcher. When there's
    # only one instance of Dispatcher, it will be possible to use the `run_async` decorator.
    with self.__singleton_lock:
        if self.__singleton_semaphore.acquire(blocking=0):
            self._set_singleton(self)
        else:
            self._set_singleton(None)


# Traceback (telegram.error.BadRequest)
<project_path>/venv/bin/python <project_path>/issue.py
2017-06-20 23:24:11,743 - __main__ - INFO - /start
2017-06-20 23:24:11,906 - telegram.ext.dispatcher - WARNING - A TelegramError was raised while processing the Update.
2017-06-20 23:24:11,907 - __main__ - ERROR - Boom!
2017-06-20 23:24:11,907 - __main__ - INFO - /async_start
2017-06-20 23:24:12,188 - telegram.utils.promise - ERROR - An uncaught error was raised while running the promise
Traceback (most recent call last):
File "<project_path>/venv/src/python-telegram-bot/telegram/utils/promise.py", line 42, in run
self._result = self.pooled_function(*self.args, **self.kwargs)
File "<project_path>/issue.py", line 25, in action_async_start
update.message.reply_text(msg, parse_mode=ParseMode.HTML)
File "<project_path>/venv/src/python-telegram-bot/telegram/message.py", line 340, in reply_text
return self.bot.send_message(self.chat_id, *args, **kwargs)
File "<project_path>/venv/src/python-telegram-bot/telegram/bot.py", line 125, in decorator
result = func(self, *args, **kwargs)
File "<project_path>/venv/src/python-telegram-bot/telegram/bot.py", line 158, in decorator
return Bot._message_wrapper(self, url, data, *args, **kwargs)
File "<project_path>/venv/src/python-telegram-bot/telegram/bot.py", line 146, in _message_wrapper
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
File "<project_path>/venv/src/python-telegram-bot/telegram/utils/request.py", line 252, in post
**urlopen_kwargs)
File "<project_path>/venv/src/python-telegram-bot/telegram/utils/request.py", line 194, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Can't parse entities in message text: unsupported start tag "invalid_tag" at byte offset 0

Process finished with exit code 0

# Fixed code
def __init__(
    self,
    bot,
    update_queue,
    workers=4,
    exception_event=None,
    job_queue=None,
    persistence=None,
    use_context=False,
):
    self.bot = bot
    self.update_queue = update_queue
    self.job_queue = job_queue
    self.workers = workers
    self.use_context = use_context

    if not use_context:
        warnings.warn(
            "Old Handler API is deprecated - see https://git.io/fxJuV for details",
            TelegramDeprecationWarning,
            stacklevel=3,
        )

    self.user_data = defaultdict(dict)
    self.chat_data = defaultdict(dict)
    self.bot_data = {}
    self._update_persistence_lock = Lock()
    if persistence:
        if not isinstance(persistence, BasePersistence):
            raise TypeError("persistence must be based on telegram.ext.BasePersistence")
        self.persistence = persistence
        if self.persistence.store_user_data:
            self.user_data = self.persistence.get_user_data()
            if not isinstance(self.user_data, defaultdict):
                raise ValueError("user_data must be of type defaultdict")
        if self.persistence.store_chat_data:
            self.chat_data = self.persistence.get_chat_data()
            if not isinstance(self.chat_data, defaultdict):
                raise ValueError("chat_data must be of type defaultdict")
        if self.persistence.store_bot_data:
            self.bot_data = self.persistence.get_bot_data()
            if not isinstance(self.bot_data, dict):
                raise ValueError("bot_data must be of type dict")
    else:
        self.persistence = None

    self.handlers = {}
    """Dict[:obj:`int`, List[:class:`telegram.ext.Handler`]]: Holds the handlers per group."""
    self.groups = []
    """List[:obj:`int`]: A list with all groups."""
    self.error_handlers = {}
    """Dict[:obj:`callable`, :obj:`bool`]: A dict, where the keys are error handlers and the
        values indicate whether they are to be run asynchronously."""

    self.running = False
    """:obj:`bool`: Indicates if this dispatcher is running."""
    self.__stop_event = Event()
    self.__exception_event = exception_event or Event()
    self.__async_queue = Queue()
    self.__async_threads = set()

    # For backward compatibility, we allow a "singleton" mode for the dispatcher. When there's
    # only one instance of Dispatcher, it will be possible to use the `run_async` decorator.
    with self.__singleton_lock:
        if self.__singleton_semaphore.acquire(blocking=0):
            self._set_singleton(self)
        else:
            self._set_singleton(None)