import asyncio


def schedule_coroutine(target):
    """Schedules target coroutine in the given event loop
    If not given, *loop* defaults to the current thread's event loop
    Returns the scheduled task.
    """
    if asyncio.iscoroutine(target):
        return asyncio.ensure_future(target, loop=asyncio.get_event_loop())
    else:
        raise TypeError("target must be a coroutine, "
                        "not {!r}".format(type(target)))