nlpub/pymystem3

Error when launch in docker

konin-sergei opened this issue · 0 comments

Hello.
I try to launch mystem in docker with multiprocessing and get error:
OSError: [Errno 26] Text file busy: '/root/.local/bin/mystem'

Dockerfile
FROM python:3.8-buster
WORKDIR /usr/src/app
COPY . .
RUN python3.8 -m pip install --upgrade pip
RUN python3.8 -m pip install --no-cache-dir pymystem3
CMD ["python3.8", "script.py"]

script.py
import multiprocessing
import time
from pymystem3 import Mystem
def lemma(data):
process_n = data[0]
texts = data[1]
print("process_n", process_n, "Создали Mystem()")
m = Mystem()
lemma_text = m.lemmatize(' '.join(texts))
m.close()
print("process_n", process_n, "Закрыли Mystem()")
return lemma_text

def lemmatisation_text():
n_core = 4
texts = ['Мама моет раму, Рама держит маму.' for x in range(1000)]
# Добавим номера процессов
params = [[core, texts] for core in range(n_core)]
print('pool start')
pool = multiprocessing.Pool(n_core)
print('pool map')
res = pool.map(lemma, params)
print('pool close')
pool.close()
print('pool join')
pool.join()
print(len(res))

if name == 'main':
start = time.time()
lemmatisation_text()
print(time.time() - start)