swiftly.concurrency

Concurrency API for Swiftly.

Copyright 2011-2013 Gregory Holt

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class swiftly.concurrency.Concurrency(concurrency=10)[source]

Bases: object

Convenience class to support concurrency, if Eventlet is available; otherwise it just performs at single concurrency.

Parameters:concurrency – The level of concurrency desired. Default: 10
get_results()[source]

Returns a dict of the results currently available. The keys are the ident values given with the calls to spawn. The values are tuples of (exc_type, exc_value, exc_tb, result) where:

exc_type The type of any exception raised.
exc_value The actual exception if any was raised.
exc_tb The traceback if any exception was raised.
result If no exception was raised, this will be the return value of the called function.
join()[source]

Blocks until all currently pending functions have finished.

spawn(ident, func, *args, **kwargs)[source]

Returns immediately to the caller and begins executing the func in the background. Use get_results and the ident given to retrieve the results of the func. If the func causes an exception, this exception will be caught and the sys.exc_info() will be returned via get_results.

Parameters:
  • ident – An identifier to find the results of the func from get_results. This identifier can be anything unique to the Concurrency instance.
  • func – The function to execute concurrently.
  • args – The args to give the func.
  • kwargs – The keyword args to the give the func.
Returns:

None

Previous topic

swiftly.client

Next topic

swiftly.dencrypt

This Page