Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrmessagewriter opened this issue May 31, 2023 · 2 comments
Open

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

mrmessagewriter opened this issue May 31, 2023 · 2 comments

Comments

@mrmessagewriter
Copy link

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.

@havok2063
Copy link
Owner

@mrmessagewriter is this still an issue? Sorry for the long delay in responding. Yeah I didn't have multi-threading in mind when initially creating the package. I can take a look but if you have a workaround or solution already implemented, feel free to submit a PR for review.

@mrmessagewriter
Copy link
Author

mrmessagewriter commented Apr 8, 2024

Ahh well yeah the solution is to wrap multiprocess to manage a group of threads, each executing as a single unique thread. It is not a great solution, but also not part of the boolean_parser itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants