Skip to content

Commit

Permalink
tiny fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Mar 11, 2021
1 parent 4cfa56e commit 9b8f616
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ostap/utils/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,21 @@ def tempdir ( suffix = '' , prefix = 'tmp-' , date = True ) :
@staticmethod
def get_temp_file ( suffix = '' , prefix = 'tmp-' , dir = None , date = True ) :
"""Generate the name for the temporary file.
- the method shodul be abvoided in favour of` CleanUp.tempfile`
- the method should be avoided in favour of `CleanUp.tempfile`
>>> fname = CleanUp.get_temp_file ()
"""
with UseTmpDir ( _TmpDir ) :
if date :
now = datetime.datetime.now()
prefix = "%s%s-" % ( prefix , now.strftime ( "%Y-%b-%d" ) )
_file = tempfile.NamedTemporaryFile ( suffix = suffix ,
prefix = prefix ,
dir = dir ,
delete = False )
fname = _file.name
_file.close()
os.unlink(fname)

with tempfile.NamedTemporaryFile ( suffix = suffix ,
prefix = prefix ,
dir = dir ,
delete = False ) as tfile :
fname = tfile.name

os.unlink ( fname )
assert not os.path.exists ( fname )
logger.verbose ( 'temporary file requested %s' % fname )
return fname
Expand Down

0 comments on commit 9b8f616

Please sign in to comment.