Skip to content

boolean_parser() does not appear to be thread safe #13

@mrmessagewriter

Description

@mrmessagewriter

Using boolean_parser to handle text parsing to convert into SQLAlchemy queries, in Flask application, I was occassionally getting the error:
TypeError: Condition.__init__() missing 1 required positional argument: 'data'
I checked through all of my code, to make sure everything was correctly formatting the input string. Everything I could find in my code was throughly vetted.
Then I thought since it was a multi threaded app, perhaps this issue laid in the parser itself. I presumed the parser would be creating a new instance of parser each time. It seems to be doing that using the "parse()" method to create the correct base parser.

However given the following code, it crashes almost immediately the same way:
`if name == 'main':

from boolean_parser import parse as boolean_parser
from multiprocessing.dummy import Pool

test_string ="(owner_id == 418f5230-365f-4867-9721-0bd498968932)"

test_list = [test_string for t in range(0, 1000)]

with Pool(5) as p:
    print(p.map(boolean_parser, test_list))

`
The multiprocessing.dummy class is the same as using the Threading class, just makes it easy to switch back and forth.
If you were to run the list through a standard map function, it would execute correctly. If you use just the multiprocessing module it also just works. I love the functionality of this package, and I can probably get a work around figured out, but would prefer to get this working. This happens in 1.4 and 1.5 beta.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions