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

Does this library support thread-safety? #47

Open
ducanh997 opened this issue May 19, 2023 · 0 comments
Open

Does this library support thread-safety? #47

ducanh997 opened this issue May 19, 2023 · 0 comments

Comments

@ducanh997
Copy link

When calling the word_segment function from multiple threads, my service sometimes encounters the following exception:

"/usr/local/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iterator                                                                                                                     ││     yield fs.pop().result()                                                                                                                                                                                     ││   File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 446, in result                                                                                                                              ││     return self.__get_result()                                                                                                                                                                                  ││   File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result                                                                                                                        ││     raise self._exception                                                                                                                                                                                       ││   File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run                                                                                                                                 │
│     result = self.fn(*self.args, **self.kwargs)                                                                                                                                                                 │
│   File "/usr/local/lib/python3.9/site-packages/py_vncorenlp/vncorenlp.py", line 95, in word_segment                                                                                                             │
│     self.model.annotate(annotation)                                                                                                                                                                             │
│   File "jnius/jnius_export_class.pxi", line 878, in jnius.JavaMethod.__call__                                                                                                                                   │
│   File "jnius/jnius_export_class.pxi", line 972, in jnius.JavaMethod.call_method                                                                                                                                │
│   File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception                                                                                                                                               │
│ jnius.JavaException: JVM exception occurred: java.util.ConcurrentModificationException         

Here is my code to call the word_segment function:

thread_pool_executor = ThreadPoolExecutor(max_workers=4)
rdrsegmenter = py_vncorenlp.VnCoreNLP(annotators=["wseg"])
segmented_contents = list(thread_pool_executor.map(rdrsegmenter.word_segment, contents))

So my question is whether this library is thread-safe or not. Note that this exception does not always occur, only occasionally.

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

1 participant