Skip to content

Commit

Permalink
fix: lazy import async_wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed May 19, 2024
1 parent eae1798 commit ee29e20
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/timeout_executor/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

from __future__ import annotations

from functools import wraps
from inspect import iscoroutinefunction
from os import environ
from pathlib import Path
from typing import Any, Callable, Coroutine

import anyio
import cloudpickle
from async_wrapper import async_to_sync
from typing_extensions import ParamSpec, TypeVar

from timeout_executor.const import TIMEOUT_EXECUTOR_INPUT_FILE
Expand All @@ -29,6 +27,8 @@ def run_in_subprocess() -> None:
new_func = output_to_file(output_file)(func)

if iscoroutinefunction(new_func):
from async_wrapper import async_to_sync

new_func = async_to_sync(new_func)

new_func(*args, **kwargs)
Expand Down Expand Up @@ -58,7 +58,6 @@ def _output_to_file_sync(
file = file._path # noqa: SLF001

def wrapper(func: Callable[P, T]) -> Callable[P, T]:
@wraps(func)
def inner(*args: P.args, **kwargs: P.kwargs) -> T:
dump = b""
try:
Expand Down Expand Up @@ -89,7 +88,6 @@ def _output_to_file_async(
def wrapper(
func: Callable[P, Coroutine[Any, Any, T]],
) -> Callable[P, Coroutine[Any, Any, T]]:
@wraps(func)
async def inner(*args: P.args, **kwargs: P.kwargs) -> T:
dump = b""
try:
Expand Down

0 comments on commit ee29e20

Please sign in to comment.