Skip to content

Commit

Permalink
Use cached version of is_coroutine_function in stream handling to
Browse files Browse the repository at this point in the history
mitigate re-checking the same function many times.

Decorate function definition, cache all function definitions.

Oops, cache is python 3.9-only

Alias duplicate function.

Use distributed's version of this util.

bad rebase.
  • Loading branch information
Ian Rose committed Feb 4, 2021
1 parent 98570fb commit 893a91f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions distributed/actor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import asyncio
import functools
from inspect import iscoroutinefunction
import threading
from queue import Queue

from .client import Future, default_client
from .protocol import to_serialize
from .utils import thread_state, sync
from .utils import iscoroutinefunction, thread_state, sync
from .utils_comm import WrappedKey
from .worker import get_worker

Expand Down
4 changes: 2 additions & 2 deletions distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ def color_of(x, palette=palette):
return palette[n % len(palette)]


@functools.lru_cache(None)
def iscoroutinefunction(f):
return inspect.iscoroutinefunction(f) or gen.is_coroutine_function(f)

Expand Down Expand Up @@ -1343,8 +1344,7 @@ def parse_ports(port):
return ports


def is_coroutine_function(f):
return asyncio.iscoroutinefunction(f) or gen.is_coroutine_function(f)
is_coroutine_function = iscoroutinefunction


class Log(str):
Expand Down

0 comments on commit 893a91f

Please sign in to comment.