import threading


def in_thread(target, args=(), name=None, daemon=True, silent=False):
    """
    Executes the given function in background.
    :param target: function
    :param args: function arguments
    :param name: name of the thread
    :param daemon: run as daemon thread, do not block until thread is doe
    :param silent: swallows exceptions raised by target silently
    :return background thread
    """
    if not isinstance(args, tuple):
        raise ValueError('args must be a tuple, not {}, for a single argument use (arg,)'
                         .format(type(args)))

    if silent:
        def fn(*args):
            try:
                target(*args)
            except:
                pass
    else:
        fn = target

    bg = threading.Thread(target=fn, args=args, name=name)
    bg.daemon = daemon
    bg.start()
    return bg