-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A lot of miscellaneous work #14
base: master
Are you sure you want to change the base?
Conversation
This further centralises socket-related errors to originate either from within Connection#_interact or Connection#connect.
`Connection#connect` is now a no-op for a non-closed connection. The closed property is not yet correctly maintained in the case of socket errors.
By making Connection inherit from threading.local, we can make a single connection object and use it from several threads, safely. This is enormously useful when using libraries like eventlet, and is common in similar libraries.
This reverts commit bd11204.
We can't use a general socket timeout because of our use of buffered socket I/O with socket.makefile(), but we can add a timeout to the part where we connect to the server, and remove the timeout once the connection succeeds.
We can get rid of the bothersome PyYaml dependency by using a very simple regexp-based parser, which happens to be a lot faster than a full YAML parser. It also allows us to work around some oddities in the way beanstalkd emits YAML: if a tube name looks like a number, the new parser will still parse it as a string, which is probably what users expect to happen.
The docstrings don't tell everything, and so there's a need for some more extensive documentation, but they serve as a basic guide to what each function does, which is very helpful.
Docstrings and README.md were wrapped at 70 columns, which was not consistent with TUTORIAL.md, and uncomfortably short.
Add a title at the top, and include a note about what exactly you can stick in a job body -- arbitrary bytes -- and how to make this play nice with Unicode.
The parser has a list of keys which it will not attempt to parse as numbers, in order to correctly parse messages from beanstalkd. The version, which may look like a number in the future, should be part of this list.
When using a connection with exponential or constant backoff, you should pass connect_automatically=False to the constructor, and call connect() manually. This may fail. If you then call connect() again, there will be a small delay before it attempts to reconnect. If it fails again, the next delay will be larger, and so on, exponentially. A successful connection resets this.
This behaves the same as the behavior in the main branch. Also, to simplify the API, it connects automatically iff the reconnect strategy is exp_backoff or constant.
Peter, thanks a lot for this contribution. I'll review and handle it in separate parts over the next few days. First up, the easiest part: the very documentation improvements are merged in 07a9b29. |
I merged the connection timeout parameter in cc22cef. This is a good idea, even independently of the reconnection stuff in Note that I made two minor modifications:
|
Any updates on this? |
I would also love to see these fixes merged. Thanks. |
Any update here? |
Dan and Dan, thanks for your comments. Is there anything specific you are particularly interested in seeing merged? |
The thread-safety stuff is the part that I personally care about the most. |
Thread-safety & reconnects for me. |
Ping. |
Hey Guys! I would love thread safety too! |
Ping |
+1 also for reconnection / thread safety @earl : is it because the PR is too big that you hesitate in going forward towards this ? how could we help you with it mate ? Thanks |
Nice project you've got! I made a bunch of changes here:
There was also a brief attempt to make connections thread-local, but that patch was reverted. The Right Thing in this case is probably to keep thread-local connection pools, like they do over in redis-py.
Anyway, you've made what is easily the best beanstalkd client for Python, so thanks for that.