File tree Expand file tree Collapse file tree 1 file changed +15
-15
lines changed
Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -708,21 +708,21 @@ def _guessplumedroot(kernel=None):
708708 dir from there.
709709 """
710710 try :
711- import tempfile
712- log = tempfile. mkstemp()[ 1 ]
713- with Plumed(kernel ) as p :
714- p.cmd( " setLogFile " , log)
715- p.cmd( " init " )
716- i = 0
717- root = " "
718- with open (log) as fin:
719- for line in fin:
720- i = i + 1
721- if re.match(" PLUMED: Root: " ,line):
722- root= re.sub(" PLUMED: Root: " ," " ,line).rstrip(" \n " )
723- break
724- if len (root)> 0 :
725- return root
711+ from tempfile import NamedTemporaryFile
712+ # mkstemp does not delete the created file, so we improvise:
713+ with NamedTemporaryFile( ) as tmpfile :
714+ log= tmpfile.name
715+ with Plumed(kernel) as p:
716+ p.cmd( " setLogFile " ,log)
717+ p.cmd( " init " )
718+ root = None
719+ with open (log) as fin:
720+ for line in fin:
721+ if re.match(" PLUMED: Root: " ,line):
722+ root= re.sub(" PLUMED: Root: " ," " ,line).rstrip(" \n " )
723+ break
724+ if root and len (root)> 0 :
725+ return root
726726 except :
727727 pass
728728 # alternative solution, search for a plumed executable in the path
You can’t perform that action at this time.
0 commit comments