Remove duplicate code (result from duplicate merge)
Move unload_community and database.commit to the stop method.
Properly wait for thread to finish even when multiple threads call stop().
__debug__ flag no longer influences the shutdown behavior.
More debug feedback.
Removing Singleton.

Singletons are used for Dispersy and Database instances.  This is not
stricly necessary and, especially when stopping Dispersy, can be
difficult to deal with.

This patch removes all Singletons from the Dispersy core.

Since Dispersy.{has,get}_instance() can no longer be used to obtain
the Dispersy instance, this instance must be given as parameters when:

- a Community is created (create_community, join_community,
  get_master_members, load_community).

- a Member is created (should now use get_member,
  get_temporary_member_from_id, get_members_from_id, and
  get_member_from_database_id)

Similarly, since DispersyDatabase.{has,get}_instance() can no longer
be used, this should be replaced with dispersy.database.
Unit test cleanup.

Moved all unittests from script.py into their own modules in the tests
directory where nosetests can find them.

The tests no longer use tool/main.py to start and stop dispersy,
instead this is done using setUpClass and tearDownClass in
dispersytestclass.py.
Member cache cleanup.

The member cache moved from the Member class (i.e. it was a global
variable) to the Dispersy instance.

This means that to access the cache, members must be obtained through
one of the Dispersy 'get_member...' methods.
Dispersy.stop() no longer calls Callback.stop().

Callback is created and started before Dispersy is made (in Tribler
this is done in the LaunchManyCore).  It should be stoped after
Dispersy is finished (in Tribler this should also be done in the
LaunchManyCore).
Removed obsolete cache code.
Removed incorrect assert.

When requesting a dispersy-identity message it is entirely possible
that we already have the public key, i.e. we downloaded it from a
different community.  We must still be able to download the
dispersy-identity messages from other communities.
Can again set the private key for an existing member.

The Member constructor is no longer called for each Member that is
returned or found in the cache (back when the cache was in
Member._cache).

Hence a new set_private_key(private_key) method is now available.
This method is called when the private_key is known but not yet
available in the cached Member instance.
Moved thread name parameter from start() to __init__().

This move is necessary to allow dispersy to start() the callback,
while not letting dispesy choose the name of the thread.

This patch also removes the prctl import that was used to prefix
"Tribler" to the thread name.  prctl is not part of standard python
hence I prefer not to use it, unless necessary.
Adds open and close methods.

Code that actually performs tasks in the database (open connection,
create tables, version check) has all moved from from __init__ into
open.

This move is necessary to allow dispersy to initialize the database
while the callback thread has not started yet.  The database will be
opend, on the callback thread, during dispersy.start.
Adds open and close methods.

These methods are necessary now that dispersy has start and stop
methods.
Adds a Dispersy.start method.

The Dispersy.__init__ method can no longer perform any tasks, aside
from creating memory structures.  All tasks (such as database access)
are delayed until Dispersy.start is called.
No longer perform the bootstrap nodes test during normal unittest runs
Murphy says our stop wouldn't always work.

Incoming data can cause communities to be loaded after we just unload
them.  For safety we will unload any 'accidentally' loaded communities
again.
Bugfix: load communities using load_community.
define_auto_load will load all communities when load=True.