Skip to content

Commit 6c00e23

Browse files
committed
Fix decorator.
1 parent 397f94d commit 6c00e23

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

openml/utils.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,26 @@ def _remove_cache_dir_for_id(key, cache_dir):
291291
'Please do this manually!' % (key, cache_dir))
292292

293293

294-
def thread_safe_if_oslo_installed(func, *args, **kwargs):
294+
def thread_safe_if_oslo_installed(func):
295295
if oslo_installed:
296-
# Lock directories use the id that is passed as either a first argument, or as a keyword.
297-
id_parameters = ['_id' in parameter_name for parameter_name in kwargs]
298-
if len(id_parameters) == 1:
299-
id_ = kwargs[id_parameters[0]]
300-
elif len(args) > 0:
301-
id_ = args[0]
302-
else:
303-
raise RuntimeError("An id must be specified for {}, was passed: ({}, {}).".format(
304-
func.__name__, args, kwargs
305-
))
306-
# The [7:] gets rid of the 'openml.' prefix
307-
lock_name = "{}.{}:{}".format(func.__module__[7:], func.__name__, id_)
308-
with lockutils.external_lock(name=lock_name, lock_path=_create_lockfiles_dir()):
309-
return func(*args, **kwargs)
296+
def safe_func(*args, **kwargs):
297+
# Lock directories use the id that is passed as either a first argument, or as a keyword.
298+
id_parameters = [parameter_name for parameter_name in kwargs if '_id' in parameter_name]
299+
if len(id_parameters) == 1:
300+
id_ = kwargs[id_parameters[0]]
301+
elif len(args) > 0:
302+
id_ = args[0]
303+
else:
304+
raise RuntimeError("An id must be specified for {}, was passed: ({}, {}).".format(
305+
func.__name__, args, kwargs
306+
))
307+
# The [7:] gets rid of the 'openml.' prefix
308+
lock_name = "{}.{}:{}".format(func.__module__[7:], func.__name__, id_)
309+
with lockutils.external_lock(name=lock_name, lock_path=_create_lockfiles_dir()):
310+
return func(*args, **kwargs)
311+
return safe_func
310312
else:
311-
return func(*args, **kwargs)
313+
return func
312314

313315

314316
def _create_lockfiles_dir():

0 commit comments

Comments
 (0)