# -*- coding=utf-8 -*-
from docx2pdf import convert
import pythoncom
import time
import os
from threading import Lock

ll = Lock()


def convert_word_to_pdf(pdf_name):
    for cccou in range(3):
        try:
            ll.acquire()
            print('加锁，进入转pdf')
            pythoncom.CoInitialize()
            convert(f'{pdf_name}.docx') 
            for i in range(30):
                if os.path.exists(f'{pdf_name}.pdf'):
                    break
                time.sleep(0.5)
            break
        except Exception as ee:
           
            print(ee)
        finally:
            pythoncom.CoUninitialize()
            print('解锁，转pdf完成')
            ll.release() 

def convert_word_to_pdf2(pdf_name):
    for cccou in range(3):
        try:
            convert(f'{pdf_name}.docx') 
            for i in range(30):
                if os.path.exists(f'{pdf_name}.pdf'):
                    break
                time.sleep(0.5)
            break
        except Exception as ee:
            print(ee)


if __name__ == '__main__':
    import multiprocessing

   
   
   

   
   
   
   
   
   
   
   
   
   
   
    #
   