Skip to content
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

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Conversation

PeterScott
Copy link

Nice project you've got! I made a bunch of changes here:

  • Merge in the wip-reconnect branch, which gives a big improvement in robustness.
  • Rename README and TUTORIAL to .md files, for GitHub user-friendliness, and expand the README.
  • Add a connection timeout. We can't do a general socket timeout, but we can add a timeout to the socket's initial connection attempt, which could be useful.
  • Get rid of the dependency on PyYaml, replacing it with a custom parser that's more compatible with beanstalkd, and about 30 times faster. Adjust documentation to match.
  • Add basic docstrings to all public methods.

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.

earl and others added 24 commits May 22, 2010 03:42
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.
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.
@earl
Copy link
Owner

earl commented Jan 28, 2011

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.

@earl
Copy link
Owner

earl commented Jan 28, 2011

I merged the connection timeout parameter in cc22cef. This is a good idea, even independently of the reconnection stuff in wip-reconnect.

Note that I made two minor modifications:

  • I renamed the parameter to connect_timeout
  • Instead of a custom default timeout, we're now falling back on socket.getdefaulttimeout (which is typically None, unless set by the user)

@arturhoo
Copy link

Any updates on this?

@dsully
Copy link

dsully commented Feb 24, 2012

I would also love to see these fixes merged.

Thanks.

@dlo
Copy link

dlo commented Mar 22, 2012

Any update here?

@earl
Copy link
Owner

earl commented Mar 22, 2012

Dan and Dan, thanks for your comments. Is there anything specific you are particularly interested in seeing merged?

@PeterScott
Copy link
Author

The thread-safety stuff is the part that I personally care about the most.

@dsully
Copy link

dsully commented Mar 23, 2012

Thread-safety & reconnects for me.

@dsully
Copy link

dsully commented Dec 13, 2012

Ping.

@hurrycane
Copy link

Hey Guys! I would love thread safety too!

@hit9
Copy link

hit9 commented Jul 29, 2014

Ping

@ultrabug
Copy link

+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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants