Skip to content

Instantly share code, notes, and snippets.

@rstuart85
Last active December 14, 2015 09:48
Show Gist options
  • Save rstuart85/5c093757d62916946fc7 to your computer and use it in GitHub Desktop.
Save rstuart85/5c093757d62916946fc7 to your computer and use it in GitHub Desktop.
# Copyright (c) 2012-2015 Kapiche Ltd.
# Author: Ryan Stuart<ryan@kapiche.com>
import logging
from multiprocessing.pool import ThreadPool
import os
import time
import uuid
import gcloudoem
from gcloud import datastore
log = logging.getLogger(__name__)
GCLOUD_JSON_KEY = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'gcloud-key-9c74539dd405.json'
)
GCLOUD_PROJECT_ID = 'research-by-kapiche'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = GCLOUD_JSON_KEY # Set location of service account creds
os.environ['GCLOUD_DATASET_ID'] = GCLOUD_PROJECT_ID # Set location of service account creds
class TestEntity(gcloudoem.Entity):
data = gcloudoem.TextProperty()
def run_gcloudoem():
gcloudoem.connect('research-by-kapiche', 'testing')
try:
entity = TestEntity(data=uuid.uuid4().hex)
entity.save()
time.sleep(1)
fetched_entity = TestEntity.objects.get(pk=entity.pk)
entity.delete()
print("GCloudOEM worked!")
except Exception as e:
log.exception("Calling datastore failed with gcloudoem")
raise e
def run_gcloud():
try:
key = datastore.Key('GCloudTest', 123)
entity = datastore.Entity(key)
entity['data'] = uuid.uuid4().hex
# Store the entity
with datastore.Transaction():
datastore.put([entity])
time.sleep(1)
query = datastore.Query(kind='GCloudTest')
list(query.fetch(limit=2))
# Delete the entity
with datastore.Transaction() as txn:
time.sleep(1)
txn.delete(key)
print("GCloud worked!")
except Exception as e:
log.exception("Calling datastore failed with gcloud_python")
raise e
if __name__ == '__main__':
logging.basicConfig(filename='gcloud_test.log', level=logging.DEBUG)
def execute(*args):
run_gcloud()
run_gcloudoem()
pool = ThreadPool(4)
pool.map(execute, [None, None, None, None])
@dhermes
Copy link

dhermes commented Nov 20, 2015

@rstuart85 What did you use to run this more than once? Did you keep track of the time or the number of iterations before the SSL error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment