New answers tagged

3

Something not included in the other answers: These two lines in your main function mean that you request and parse each page twice. It also means your code is not really async, because you loop over all fabrics and just await each of them. You should be able to just remove the first one. await fetch_pricing_data(session, pricing_url) tasks.append(asyncio....


8

While you can put request parameters in the URI directly, it's usually neater to pass those using the params argument of session.get. So for example pricing_url could just be "https://api-gateway.spoonflower.com/alpenrose/pricing/fabrics/FABRIC_" + fab_type and you could pass the rest as params={"quantity": 1, "shipping_country":...


2

I'm not too experienced with asyncio, but I have a couple of minor observations about your program. It is a code smell in modern Python to use an int to index over an array. Instead of for index in range(len(fabric)): You could say for fabric_type in fabric: Another observation in that you are using naked except blocks instead of catching "KeyError&...


2

SemaphoreSlim provides async locking out-of-the-box. using var semaphore = new SemaphoreSlim(1); // ... await semaphore.WaitAsync(); try { // critical section code } finally { semaphore.Release(); } Is this really better than traditionally used locks? Nope. Because you're just wrapping monitors with new Task instance spawn. It could be ...


1

Not a review but an alternative solution to leave here. Just because the above one is overkill, as for me. Probably you want to implement Publisher/Subscriber pattern in awaitable/Command mode. But it's possible using delegate itself. Consider the extension method public static class DelegateExtensions { public static Task InvokeAsync<TArgs>(this ...


Top 50 recent answers are included