tl;dr: Think about exceptions when writing a context manager.
I made a huge unforced error with a context manager at work.
We use Redis distributed locks for system synchronization. I wanted a context manager that acquired n locks, executed protected code, and then released the n locks in reverse order. It would be simple to use:
from common.util import Semaphore, distlock
semaphore1 = Semaphore(OwnerDisambiguationUpdate.UPDATE_LOCK)
semaphore2 = Semaphore(USMaintenanceFeeUpdate.UPDATE_LOCK)
with distlock(semaphore1, semaphore2):
(The Semaphore class does other work with aborting Celery tasks, but that’s not germane here. It’s a Redis distributed lock with extra fanciness.)
We had more fun with a vendor today.
We license a vendor’s services for corporate information, like annual revenue and office locations. Their name shall be kept confidential. I’ve written about them before.
About two weeks ago, we noticed a slowdown in our API calls into their system.
We asked them about it, and they replied that they would take a look. A bit later, they said they had found the problem and were working on a solution.
Today, after working on new code, I ran my unit tests. A few tests make calls to this vendor. (Yeah, I could have mocked out the calls. But there are good reasons to not mock out calls in unit tests.) I was surprised to see those tests now fail.
Curiously, they failed because the API calls returned the response, “Customer Disabled”.
I immediately switched to a browser window and tried a part of our product that used their API. I found that our product now failed with the same error. Uh oh.
I e-mailed the vendor and asked what’s up. Their answer:
We found that our service was being slowed down by your API calls. So we disabled your API key.
I am not kidding. Continue reading after you’ve caught your breath.
Now and then, I regret the tip I’ve left at a restaurant. Virtually every time this happens it’s because I thought I had been a little cheap.
The server did a great job, the pre-tax total was $24.00, and I left $4.75. Or the server did an OK job, the pre-tax total was $36.00, and I left $5.00 or $5.25.
I saved myself 25 cents or whatever. Big deal! The savings won’t affect my lifestyle. What am I trying to prove?
That extra bit would mean more to the server than it would to me. I enjoy giving money to street performers, so why don’t I tip better in restaurants?
Maybe because, like some people, I think tipping is a silly custom. Maybe that’s what it is: I think it’s silly but go along with it anyway, because that’s how we conduct restaurant business in the US.
By not liking it, but doing it anyway and being cheap, I’m not making anyone happy. I’m not delighting the server, and I’m giving myself a mental itch. I need to get off the fence and pick one side or the other. Either don’t tip at all, or, do it right.
I’ll start tipping better from this moment forward. When in doubt, I’ll round up. There. Side chosen!
An update to an earlier post…
We’ve had problems using the pyrax SDK, mostly in account authentication.
First, it wasn’t at all clear when, or under what conditions, we had to re-authenticate our pyrax token. As documented, after you initially authenticate your credentials, pyrax handles all subsequent re-authentication under the covers. I.e., it will automatically re-authenticate the token if it ever expires.
This is kind of odd. I don’t understand why a good token should need re-authentication.
We then discovered that pyrax sometimes can’t re-authenticate our token! Every 19 hours, we hit a period of about five hours when our token won’t automatically authenticate. Why? I still don’t have a clear answer. Some authentication server, somewhere, clearly gets confused. You won’t run into this bug if you don’t have long-running processes. But, we do.
How do you differentiate delusional vs. visionary?
A person has an idea, everyone says she’s delusional and the idea sucks, it fails, they say I told you so. But if it succeeds, they trip over themselves saying how visionary she was and the idea was brilliant.
The ends should never justify the means. But they often justify the post hoc historical judgement.
This irks me.
The view from a friend’s Lake Union condo. Gosh, I love living here!
We host IP Street’s SAAS product at Rackspace. We’re finally taking the plunge and upgrading from python-cloudfiles to pyrax. We didn’t have any big issues with python-cloudfiles, but I was tiring of getting the brush-off from Rackspace when we asked for help with an API failure.
The benefits of keeping a technology up-to-date far outweighs the costs, unless you’re in an extreme corner case with a very unreliable vendor. Better performance, bug fixes, better capabilities, better support… all good stuff.