Skip to content

Not thread safe #812

Closed
Closed

Description

@vbraun

I'm getting occasional not reproducable errors (with the same markdown source) when running on Appengine:

Traceback (most recent call last):
[...]
  File "/base/data/home/apps/.../deps/markdown/__init__.py", line 375, in convert
    newRoot = treeprocessor.run(root)
  File "/base/data/home/apps/.../deps/markdown/treeprocessors.py", line 330, in run
    self.ancestors.pop()
IndexError: pop from empty list

I'm having threading enabled (GAE default), and TreeProcessor has a global ancestors stack. So presumably this crashes because simultaneous threads run the markdown processor. I can't find anything in the docs whether python-markdown is supposed to be thread safe, so thats either a documentation request or a bug ;-)

Activity

  1. facelessuser commented on Apr 5, 2019

    @facelessuser
    Collaborator

    Are running multiple threads on a single instance of the Markdown class? Or a separate instance in a separate thread? It is kind of unclear on what exactly you are doing.

    With that said, there has been no effort to guarantee thread safety, especially when you consider that you can pull in any custom extension which may or may not also be thread safe.

    Personally, I would not rely on Python Markdown being thread safe.

  2. waylan commented on Apr 5, 2019

    @waylan
    Member

    We have never put any work into testing or verifying if Python-Markdown is thread safe. Personally I have no idea if it is or not.

    Curious, how are you calling Markdown? Do you call the markdown.markdown wrapper which creates a new class instance on each call, or are you creating a single class instance and then calling convert for each request? I would expect the former to be more thread safe than the later.

  3. vbraun commented on Apr 8, 2019

    @vbraun
    Author

    Indeed, I have a Markdown singleton (with some custom extensions) that all threads access.

    So to summarize:

    • A Markdown instance has internal parse state and is not thread-safe
    • Thread-local Markdown instances (e.g. instantiating it in the thread) is thread-safe
  4. waylan commented on Apr 8, 2019

    @waylan
    Member

    So to summarize:

    • A Markdown instance has internal parse state and is not thread-safe
    • Thread-local Markdown instances (e.g. instantiating it in the thread) is thread-safe

    That is correct. I suppose we should document that.

  5. added
    docsRelated to the project documentation.
    on Apr 8, 2019
  6. added a commit that references this issue on Nov 25, 2019
    1cb3d02
  7. added this to the Version 3.2 milestone on Nov 25, 2019
  8. added a commit that references this issue on Nov 25, 2019
    ec7e200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsRelated to the project documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions