From 75251151ffbdd7c5b49df04ef2da28f8d1bd7c3e Mon Sep 17 00:00:00 2001 From: GUAN Xin Date: Mon, 19 Jul 2021 14:12:03 +0800 Subject: [PATCH] Some shutil don't have the .which method. Directly calling subprocess.Popen without checking the presence of the program is the optimal solution because: 1) Avoids race condition, where the program disappears between the check and the Popen call. 2) Popen will raise exception if the program is absent anyway, no race condition here. --- src/Mod/Draft/importDWG.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Mod/Draft/importDWG.py b/src/Mod/Draft/importDWG.py index 7e20be076e..29fc05d4c8 100644 --- a/src/Mod/Draft/importDWG.py +++ b/src/Mod/Draft/importDWG.py @@ -203,14 +203,15 @@ def convertToDxf(dwgfilename): """ import os, tempfile, subprocess, sys - import shutil - if shutil.which("dwg2dxf"): + try: outdir = tempfile.mkdtemp() basename = os.path.basename(dwgfilename) result = outdir + os.sep + os.path.splitext(basename)[0] + ".dxf" proc = subprocess.Popen(("dwg2dxf", dwgfilename, "-o", result)) proc.communicate() return result + except: + pass teigha = getTeighaConverter() if teigha: