Skip to content

Instantly share code, notes, and snippets.

@hiway
Created February 28, 2017 21:40
Show Gist options
  • Save hiway/71f87d097172343793262313482c0d05 to your computer and use it in GitHub Desktop.
Save hiway/71f87d097172343793262313482c0d05 to your computer and use it in GitHub Desktop.
Boilerplate code for iscoroutinefunction() to detect `async def`s
# $ micropython -m upip install micropython-inspect
try: # python 3.5+
from inspect import iscoroutinefunction
import asyncio
except ImportError: # micropython 1.8+
from inspect import isgeneratorfunction
import uasyncio as asyncio
def iscoroutinefunction(func):
return isgeneratorfunction(func) or repr(func).startswith('<closure <generator')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment