# Path: starlette/concurrency.py
# async def run_in_threadpool(
#     func: typing.Callable[P, T], *args: P.args, **kwargs: P.kwargs
# ) -> T:
#     if kwargs:  # pragma: no cover
#         # run_sync doesn't accept 'kwargs', so bind them in here
#         func = functools.partial(func, **kwargs)
#     return await anyio.to_thread.run_sync(func, *args)


import asyncio
import sys
import typing
    from typing import ParamSpec
    from typing_extensions import ParamSpec
from starlette.concurrency import run_in_threadpool

if sys.version_info >= (3, 10):  # pragma: no cover
else:  # pragma: no cover


P = ParamSpec("P")


class BackgroundTask:
    def __init__(
        self, func: typing.Callable[P, typing.Any], *args: P.args, **kwargs: P.kwargs
    ) -> None:
        self.func = func
        self.args = args
        self.kwargs = kwargs
        self.is_async = asyncio.iscoroutinefunction(func)

    async def __call__(self) -> None:
        if self.is_async:
            await self.func(*self.args, **self.kwargs)
        else:

# Path: starlette/concurrency.py
# async def run_in_threadpool(
#     func: typing.Callable[P, T], *args: P.args, **kwargs: P.kwargs
# ) -> T:
#     if kwargs:  # pragma: no cover
#         # run_sync doesn't accept 'kwargs', so bind them in here
#         func = functools.partial(func, **kwargs)
#     return await anyio.to_thread.run_sync(func, *args)


# Path: starlette/background.py
import asyncio
import sys
import typing
    from typing import ParamSpec
    from typing_extensions import ParamSpec
from starlette.concurrency import run_in_threadpool


if sys.version_info >= (3, 10):  # pragma: no cover
else:  # pragma: no cover


P = ParamSpec("P")


class BackgroundTask:
    def __init__(
        self, func: typing.Callable[P, typing.Any], *args: P.args, **kwargs: P.kwargs
    ) -> None:
        self.func = func
        self.args = args
        self.kwargs = kwargs
        self.is_async = asyncio.iscoroutinefunction(func)

    async def __call__(self) -> None:
        if self.is_async:
            await self.func(*self.args, **self.kwargs)
        else:

            await run_in_threadpool(self.func, *self.args, **self.kwargs)