This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # from http://sdiehl.github.io/gevent-tutorial/ | |
| from gevent import sleep | |
| from gevent.pool import Pool | |
| from gevent.coros import BoundedSemaphore | |
| sem = BoundedSemaphore(4) # only allows 4 greenlets at one time, others must wait until one is released | |
| def worker1(n): | |
| sem.acquire() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # based on http://sdiehl.github.io/gevent-tutorial/ | |
| import gevent | |
| import random | |
| start = time.time() | |
| tic = lambda: 'at %1.1f seconds' % (time.time() - start) | |
| def task(pid): | |
| """ | |
| Some non-deterministic task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person(object): | |
| def __init__(self,fname='', lname=''): | |
| self.fname = fname | |
| self.lname = lname | |
| def __repr__(self): | |
| return 'repr: '+ self.fname + ' ' + self.lname | |
| def __str__(self): | |
| return 'str: ' + self.fname + ' ' + self.lname | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person(object): | |
| def __init__(self,fname='', lname=''): | |
| self.fname = fname | |
| self.lname = lname | |
| def __repr__(self): | |
| return 'repr: '+ self.fname + ' ' + self.lname | |
| def __str__(self): | |
| return 'str: ' + self.fname + ' ' + self.lname | |