Created
April 16, 2018 02:49
-
-
Save ssdemajia/2a7c64b3879ab26a3b52e02634d289da to your computer and use it in GitHub Desktop.
python协程
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def coroutine(func): | |
""" | |
装饰器,用来预激活协程,协程用之前需要用next来激活 | |
""" | |
@wraps(func) | |
def primer(*args, **kwargs): | |
gen = func(*args, **kwargs) | |
next(gen) # 激活 | |
return gen | |
return primer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment