Set a connection timeout for Boto to prevent cloud storage deadlock
This commit is contained in:
parent
a1436bfebb
commit
d8f5e41fca
|
@ -1,10 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
|
import socket
|
||||||
from boto.s3.connection import S3Connection
|
from boto.s3.connection import S3Connection
|
||||||
from boto.s3.key import Key
|
from boto.s3.key import Key
|
||||||
|
|
||||||
STORAGE_BACKEND_FILE = "file"
|
STORAGE_BACKEND_FILE = "file"
|
||||||
|
SOCKET_TIMEOUT = 240
|
||||||
|
|
||||||
class CloudStorageUploader:
|
class CloudStorageUploader:
|
||||||
""" A class that uses Python-Boto SDK to upload objects into Amazon S3.
|
""" A class that uses Python-Boto SDK to upload objects into Amazon S3.
|
||||||
|
@ -88,6 +90,10 @@ class CloudStorageUploader:
|
||||||
|
|
||||||
resource_id = "%s/%s/%s_%s%s" % (metadata['file_prefix'], unique_id_prefix, file_name, unique_id, extension)
|
resource_id = "%s/%s/%s_%s%s" % (metadata['file_prefix'], unique_id_prefix, file_name, unique_id, extension)
|
||||||
|
|
||||||
|
# Boto uses the "global default timeout" by default, which is infinite! To prevent network problems from
|
||||||
|
# turning into deadlocks, we explicitly set the global default timeout period here:
|
||||||
|
socket.setdefaulttimeout(SOCKET_TIMEOUT)
|
||||||
|
|
||||||
conn = S3Connection(self._api_key, self._api_key_secret, host=self._host)
|
conn = S3Connection(self._api_key, self._api_key_secret, host=self._host)
|
||||||
bucket = conn.get_bucket(self._bucket)
|
bucket = conn.get_bucket(self._bucket)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue