Test if function or method is normal or asynchronous

后端 未结 4 1630
野的像风
野的像风 2020-12-14 14:09

How can I find out if a function or method is a normal function or an async function? I would like my code to automatically support normal or async callbacks and need a way

4条回答
  •  我在风中等你
    2020-12-14 14:52

    If you don't want to introduce another import with inspect, iscoroutine is also available inside asyncio.

    import asyncio
    
    def isAsync(someFunc):
        return asyncio.iscoroutinefunction(someFunc)
    

提交回复
热议问题