earl / beanstalkc

A simple beanstalkd client library for Python
Apache License 2.0
457 stars 115 forks source link

Can I use multiple tubes in parallel? #45

Closed ghost closed 10 years ago

ghost commented 10 years ago

can i use multiple tubes like 'spam' and 'eggs' parallel? so i can reserve job from ['spam'] and from ['eggs'] at same time on same connection.

Doerge commented 10 years ago

Yes. Call watch(...) with 'spam' and 'eggs', then call reserve. You can check out the tutorial for an example. https://github.com/earl/beanstalkc/blob/master/TUTORIAL.mkd

ghost commented 10 years ago

Thanks. But i want to retrieve job parallel like my one thread get job from ['spam'] and another get job from ['eggs'] at the same time. not one by one. is it possible? please give some guidance.

Doerge commented 10 years ago

Reserve is blocking until a msg is received, except if you have set a timeout. You can either open multiple connections or set a timeout and change which tube you are watching. For your two-thread scenario, I would go with multiple connections.

ghost commented 10 years ago

basically there are 1000 files ready to copy from one space to another. i want to copy them in parallel in 100 files chunk like in one tube first 100, in second tube another 100 and so on. I want to perform parallel copy operation from all tubes at same time. BTW thanks for sharing point of open multiple connections. is there any limitation for to open multiple connections?

earl commented 10 years ago

beanstalkc itself is not thread-safe. So whenever you want to use beanstalkc from multiple threads, you either have to do your own locking, or use the one-connection-per-thread pattern @Doerge suggested.

There's no inherent limitation in beanstalkc for the number of open connections. So the only limitations will be those imposed by your operating system and/or TCP stack (as a rough guideline: typically up to 64K connections per single client).