sardine
sardine copied to clipboard
Swimming Function Definition and Scopes
Example to understand the issue :
def intro():
@swim
def test(p=0.5,i=0):
D("bd",i=i)
again(test,p=0.5,i=i+1)
intro() #calling the swimming function inside intro()
silence(test) #doesn't silence test
This is indeed a bug. I don't really know what to do with it. I should probably take care of keeping reference to all asyncrunners
in a data structure somewhere. Not urgent for the moment but if more people start to use similar patterns, I'll try to update and fix.
This is not really an issue but has to do with the scope of function definition. See the following:
def intro():
@swim
def test(p=0.5,i=0):
D("bd",i=i)
again(test,p=0.5,i=i+1)
return test
my_runner = intro()
This example returns the function in the main scope. However, it is true that this runner is now special in the sense that it is not available as a global variable. There is probably a clever hack to implement but I wasn't able to find it.. yet.