Merge pull request #51264 from gtmanfred/2018.3

an argument is not always needed to be passed to open a file
This commit is contained in:
Pedro Algarvio 2019-01-24 07:55:25 +00:00 committed by GitHub
commit 253f5e4608
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -416,11 +416,13 @@ def flopen(*args, **kwargs):
'''
Shortcut for fopen with lock and context manager.
'''
with fopen(*args, **kwargs) as f_handle:
filename, args = args[0], args[1:]
writing = 'wa'
with fopen(filename, *args, **kwargs) as f_handle:
try:
if is_fcntl_available(check_sunos=True):
lock_type = fcntl.LOCK_SH
if 'w' in args[1] or 'a' in args[1]:
if args and any([write in args[0] for write in writing]):
lock_type = fcntl.LOCK_EX
fcntl.flock(f_handle.fileno(), lock_type)
yield f_handle