Openpyxl不适用于Windows 10的Celery-WindowsError:[错误32]

时间:2019-12-11 23:03:32

标签: windows celery openpyxl

我有Django网页,该网页使用openpyxl包创建电子表格。它使用RabbitMQ消息代理将请求发送到创建电子表格的Celery工作人员。我切换了PC并加载了最新的软件包,但是现在我的应用程序失败了。我针对该问题创建了一个小测试案例,该案例仅以Celery / Openpyxl交互为中心。我在Windows 10 PC上安装了Celery v4.3.0,Openpyxl v2.6.4和Python 2.7.13。我曾在以前的Windows 10 PC上进行过这项工作,但不知道各种版本是什么。

from celery   import Celery
from openpyxl import Workbook

app = Celery('tasks',
             backend='rpc',
             broker='amqp://localhost:5672')

app.conf.update(
    CELERY_TASK_SERIALIZER='json',
    CELERY_ACCEPT_CONTENT=['json'],
    CELERY_RESULT_SERIALIZER='json',
    CELERY_MESSAGE_COMPRESSION='gzip',
    CELERY_IGNORE_RESULT=False,
)


@app.task
def test(value):
    print 'in test'

    book = Workbook()
    sheet = book.active
    sheet['A1'] = value

    print 'before save'
    book.save("sample.xlsx")
    print 'after save'

    return True

######################################################################

In command prompt
    CD to the test directory where this code is located
    celery --app=tasks worker --loglevel=info -P eventlet

In another command prompt
    python
    from tasks import test
    t = test.delay(100)
    t.status

######################################################################

This is the traceback I get from the celery process:

[2019-12-11 16:34:10,841: WARNING/MainProcess] in test
[2019-12-11 16:34:10,841: WARNING/MainProcess] before save
[2019-12-11 16:34:10,855: ERROR/MainProcess] Task tasks.test[6f978b61-8656-433d-b383-f3b2e024df5e] raised unexpected: WindowsError(32, 'The process cannot access the file because it is being used by another process')
Traceback (most recent call last):
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\celery\app\trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\celery\app\trace.py", line 648, in __protected_call__
    return self.run(*args, **kwargs)
  File "D:\Data\Celery_test\test_openpyxl\tasks.py", line 44, in test
    book.save("sample.xlsx")
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\workbook\workbook.py", line 409, in save
    save_workbook(self, filename)
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\writer\excel.py", line 294, in save_workbook
    writer.save()
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\writer\excel.py", line 276, in save
    self.write_data()
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\writer\excel.py", line 76, in write_data
    self._write_worksheets()
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\writer\excel.py", line 216, in _write_worksheets
    self.write_worksheet(ws)
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\writer\excel.py", line 200, in write_worksheet
    writer = WorksheetWriter(ws)
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\worksheet\_writer.py", line 52, in __init__
    out = create_temporary_file()
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\site-packages\openpyxl\worksheet\_writer.py", line 38, in create_temporary_file
    prefix='openpyxl.', delete=False)
  File "c:\tools\winpython-64bit-2.7.13.1zero\python-2.7.13.amd64\lib\tempfile.py", line 480, in NamedTemporaryFile
    _os.unlink(name)

`

0 个答案:

没有答案