def execute((R, function, args, kwargs)):
R.result = apply(function, args, kwargs)
while R.result is NoResult:
Then block on the condition, and have the lambda/delegate in the idle thread signal the condition. Make sure you hold the lock for the conditions mutex before sending the message though so that it is not a race condition.
callback = SomeFunc
# ran in main