4 ms·
I’m very uninformed when it comes to async in Python so please bear with me. Given a “web API type” python app, where about 30% of the APIs also reach out to o
by holografix 6y ago
I’m very uninformed when it comes to async in Python so please bear with me.
Given a “web API type” python app, where about 30% of the APIs also reach out to other, external APIs, before responds to the incoming requests...
Is that _the_ classic example where async would provide a solid benefit?
Is that why Node has become so popular = it’s all json + non blocking API responses?
- hansvm 6y agoThat's where it _could_ provide a solid benefit (though you could probably usually do better by instantiating an appropriately sized thread pool and avoiding async entirely), but that's missing the real power of async which is that it makes concurrency easier to reason about. Except at an await the application behaves serially; you can't get interrupted in between lines or in the middle of an operation that it turns out isn't atomic.
- arethuza 6y ago"it makes concurrency easier to reason about" Doesn't it do that by not really having concurrency? There is only a single locus of control so a whole class of problems should simply cease to exist.
- hansvm 6y agoWe might be nit-picking definitions, but I don't think that's a fair characterization. From the perspective of the user programming with async, when you gather the results of two coroutines you don't care at all the order used for each stack frame. The mental model is one of concurrent operations which might suspend at yield points.
- divbzero 6y agoYes, the “web API type” app you describe is a classic example. Asynchronous Python is similar to async/await in C# or the non-blocking patterns in JS.