You will have to create a connection pool as a resident thread.
Briefly, a connection pool will take care of:
- Create a new connection if there is no connection available.
- Reuse a connection if possible.
- Remove connections that are no longer being used or that commanded
to close.
Then, your code will have have to communicate with the connection
pool. Example code:
# The connection_pool is smart enough to reuse a connection if it is
in the pool
ftp_connection = connection_pool.get_connection(server, user, pass)
current_dir = ftp_connection.getcwd()
dir_contents =
ftp_connection.ls()
ftp_connection.rm(file)
You have a similar implementation here:
http://forum.codecall.net/python-tutorials/41844-object-pooling-python.html