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

Multiprocess error triggers while trying example code #23

Closed
Ch41r05 opened this issue Aug 24, 2023 · 3 comments
Closed

Multiprocess error triggers while trying example code #23

Ch41r05 opened this issue Aug 24, 2023 · 3 comments

Comments

@Ch41r05
Copy link

Ch41r05 commented Aug 24, 2023

Hi AmenRa,

First of all I'd like to thank you for your efforts.
I'm trying to use retriv, but when I use the sample code you provided in the readme, I get the following error:

Building TDF matrix:   0%|                                                                                                                                                               | 0/4 [00:00<?, ?it/s]    vocabulary, X = self._count_vocab(raw_documents, self.fixed_vocabulary_)
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\sklearn\feature_extraction\text.py", line 1268, in _count_vocab
    for doc in raw_documents:
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\tqdm\std.py", line 1182, in __iter__
    for obj in iterable:
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multipipe\multipipe.py", line 28, in to_generator
    with Pool(n_threads) as pool:
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\context.py", line 119, in Pool
    return self._repopulate_pool_static(self._ctx, self.Process,
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\pool.py", line 329, in _repopulate_pool_static
    w.start()
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\context.py", line 336, in _Popen
    return Popen(process_obj)
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\mcelli\Documents\Training\Python\cosinematrix\venv\lib\site-packages\multiprocess\spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
    return Pool(processes, initializer, initargs, maxtasksperchild,

By just running the example code:

# Note: SearchEngine is an alias for the SparseRetriever
from retriv import SearchEngine

collection = [
  {"id": "doc_1", "text": "Generals gathered in their masses"},
  {"id": "doc_2", "text": "Just like witches at black masses"},
  {"id": "doc_3", "text": "Evil minds that plot destruction"},
  {"id": "doc_4", "text": "Sorcerer of death's construction"},
]

se = SearchEngine("new-index").index(collection)

se.search("witches masses")

Could you please help me fix this issue?

@AmenRa
Copy link
Owner

AmenRa commented Aug 24, 2023

Hi, I cannot reproduce.
I freshly installed retriv and its working correctly in my environment.
I suspect it's an issue related to your operating system (see this).

Let me know if the following snippet works:

from retriv import SearchEngine

def main():
    collection = [
      {"id": "doc_1", "text": "Generals gathered in their masses"},
      {"id": "doc_2", "text": "Just like witches at black masses"},
      {"id": "doc_3", "text": "Evil minds that plot destruction"},
      {"id": "doc_4", "text": "Sorcerer of death's construction"},
    ]
    
    se = SearchEngine("new-index").index(collection)
    
    results = se.search("witches masses")
    print(results)

if __name__ == '__main__':
    main()

@Ch41r05
Copy link
Author

Ch41r05 commented Aug 24, 2023

Thanks @AmenRa , that was my case, stupidly forgot to check if that clause was there.

@Ch41r05 Ch41r05 closed this as completed Aug 24, 2023
@AmenRa
Copy link
Owner

AmenRa commented Aug 24, 2023

You are welcome!
Please, consider giving retriv a star if you like it.

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