diff --git a/vdirsyncer/cli/fetchparams.py b/vdirsyncer/cli/fetchparams.py index ebdceff..cbd76b8 100644 --- a/vdirsyncer/cli/fetchparams.py +++ b/vdirsyncer/cli/fetchparams.py @@ -4,7 +4,7 @@ import click from . import AppContext from .. import exceptions, log -from ..utils import expand_path +from ..utils import expand_path, synchronized SUFFIX = '.fetch' @@ -31,6 +31,7 @@ def expand_fetch_params(config): return config +@synchronized() def _fetch_value(opts, key): if not isinstance(opts, list): raise ValueError('Invalid value for {}: Expected a list, found {!r}.' diff --git a/vdirsyncer/utils/__init__.py b/vdirsyncer/utils/__init__.py index bd2eace..37e2d13 100644 --- a/vdirsyncer/utils/__init__.py +++ b/vdirsyncer/utils/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import functools import os import sys import uuid @@ -178,3 +179,17 @@ def generate_href(ident=None, safe=SAFE_UID_CHARS): return to_unicode(uuid.uuid4().hex) else: return ident + + +def synchronized(lock=None): + if lock is None: + from threading import Lock + lock = Lock() + + def inner(f): + @functools.wraps(f) + def wrapper(*args, **kwargs): + with lock: + return f(*args, **kwargs) + return wrapper + return inner