On Thursday 24 November 2016 15:55, Frank Millman wrote: > "Steve D'Aprano" wrote in message > news:583653bb$0$1603$c3e8da3$54964...@news.astraweb.com... > >> Even if the computation of the memoised value is done asynchronously, you >> can easily split the computation off to a separate method (as you already >> talked about doing!) and make getval() block until it returns. > > Surely that defeats the whole purpose of asyncio. Anything that blocks holds > up the entire process. I strenuously try to avoid blocking in any shape or > form.
Perhaps I'm not understanding your task correctly, but surely you have to wait for the computation to occur at some point? Even if that's just you hitting Refresh waiting for the value of the column to eventually show up. I'm a newbie to asyncio, but if I were doing this using threads, I'd have getval() set the self._cached_value to "pending..." (say), start the computation thread running, and then return. The computation thread will eventually write the true value to _cached_value, and in the meantime the getval() method (and hence __str__ will happily use the "pending..." value. The only tricky part is to make sure you only start the thread once. -- Steven 299792.458 km/s — not just a good idea, it’s the law! -- https://mail.python.org/mailman/listinfo/python-list