Skip to content

Instantly share code, notes, and snippets.

@rtomaszewski
rtomaszewski / gil_threads_test.py
Created July 31, 2012 20:39
An example of multithreaded python code that creates about 500 long running threads
import threading
import datetime
import time
from random import random
class ThreadClass(threading.Thread):
def set_id(self, id):
self.id=id
def dummy_delay(self):
@rtomaszewski
rtomaszewski / example_debug.py
Created July 29, 2012 19:41
Primitive logging functions in your python scripts that are buffered before will be printed on the stdout
# Try to execute the script in two different modes to see the difference
#
# $ python log.py | tee log
# <noting for a long time>
#
# $ python -u log.py | tee log
# my log message 0
#
import time
@rtomaszewski
rtomaszewski / naive_cloud_api_limits.py
Created July 29, 2012 17:53
Naive API trying to create too many cloud server
def cs_create(self, count, sample_nr):
name='test' + str(int(time.time()))
image=112
flavor=1
log("[%2d][%2d] creating image: " % (sample_nr, count) + pformat( {'name': name, 'image' : image, 'flavor' : flavor } ) )
sm=self.cs.servers
server=sm.create(name, image, flavor)
@rtomaszewski
rtomaszewski / cloud_api_limits.py
Created July 29, 2012 17:49
Be aware of the cloud API limitations when creating cloud servers
# example code that creates cloud server and try not to hit the cloud API climits
cs_count=13 # number of cs to build
build_nr=1
delayed_10s=False
while build_nr <= cs_count :
if 0==build_nr % 11 and not delayed_10s:
time.sleep(60+10)