Skip to content

Commit

Permalink
Merge pull request #88 from boto/threading-doc
Browse files Browse the repository at this point in the history
Add multithreading info to the documentation.
  • Loading branch information
danielgtaylor committed Apr 15, 2015
2 parents 3f58914 + ead0509 commit 92a0b62
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/source/guide/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ the ``load`` or ``reload`` action. Examples of attributes::
.. warning::

Attributes may incur a load action when first accessed. If latency is
a concern, then manually calling ``load`` will allow you to control
a concern, then manually calling ``load`` will allow you to control
exactly when the load action (and thus latency) is invoked. The
documentation for each resource explicitly lists its attributes.

Expand Down Expand Up @@ -185,3 +185,20 @@ keyword arguments. Examples of waiters include::

# EC2: Wait for an instance to reach the running state.
instance.wait_until_running()


Multithreading
--------------
It is recommended to create a resource instance for each thread in a multithreaded application rather than sharing a single instance among the threads. For example::

import boto3
import boto3.session
import threading

class MyTask(threading.Thread):
def run(self):
session = boto3.session.Session()
s3 = session.resource('s3')
# ... do some work with S3 ...

In the example above, each thread would have its own Boto 3 session and its own instance of the S3 resource. This is a good idea because resources contain shared data when loaded and calling actions, accessing properties, or manually loading or reloading the resource can modify this data.

0 comments on commit 92a0b62

Please sign in to comment.