[Fixed]-Django server crashes with exit codes 139, 77

1👍

Okay, that was a bug in templated_docs. I was right, it happens because templated_docs is trying to start LibreOffice twice. As it said in pylokit documentation:

The use of _exit() instead of default exit() is required because in
some circumstances LibreOffice segfaults on process exit.

It means the process that used pylockt should be killed after. But we cannot kill Django server. So I decided to use multiprocessing:

# templated_docs/__init__.py

if source_extension[1:] != output_format:
    lo_path = getattr(
        settings,
        'TEMPLATED_DOCS_LIBREOFFICE_PATH',
        '/usr/lib/libreoffice/program/')

    def f(conn):
        with Office(lo_path) as lo:
            conv_file = NamedTemporaryFile(delete=False,
                                           suffix='.%s' % output_format)
            with lo.documentLoad(str(dest_file.name)) as doc:
                doc.saveAs(conv_file.name)
            os.unlink(dest_file.name)
            conn.send(conv_file.name)
            conn.close()

    parent_conn, child_conn = Pipe()
    p = Process(target=f, args=(child_conn,))
    p.start()
    conv_file_name = parent_conn.recv()
    p.join()

    return conv_file_name
else:
    return dest_file.name

I oppened an issue and made a pull request.

👤Viktor

Leave a comment