本文整理汇总了Python中threading.BoundedSemaphore类的典型用法代码示例。如果您正苦于以下问题:Python BoundedSemaphore类的具体用法?Python BoundedSemaphore怎么用?Python BoundedSemaphore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BoundedSemaphore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
class CGSBoundedSemaphore:
def __init__(self,value):
self.boundedSemaphore = BoundedSemaphore(value)
self.datasetQueueLock = RLock()
self.datasetQueue = []
def acquire(self,datasetId):
try:
self.datasetQueueLock.acquire()
self.datasetQueue.append(datasetId)
finally:
self.datasetQueueLock.release()
self.boundedSemaphore.acquire()
def release(self,datasetId):
try:
self.datasetQueueLock.acquire()
self.datasetQueue.remove(datasetId)
except:
pass
finally:
self.datasetQueueLock.release()
self.boundedSemaphore.release()
def getIndexDatasetId(self,datasetId):
try:
self.datasetQueueLock.acquire()
return self.datasetQueue.index(datasetId)
except:
return -1
finally:
self.datasetQueueLock.release()
def status(self):
return list(self.datasetQueue)
开发者ID:kosio,项目名称:EpiExplorer,代码行数:35,代码来源:DatasetProcessorManager.py
示例2: create_document
def create_document(main_url, max_connections=2, filepath=None):
"""Creates an EPUB document from a fanfic.
main_url -- user given URL which should be the first chapter
max_connections -- maximum number of simultaneous connections
default: 2. This should be chosen with care as the Terms of Service
of some of the websites states that you shouldn't cause more stress
than a normal visitor.
filepath -- optional path for the resulting Epub document
By default filename is: %author - %title.epub in the current
directory. %author and %title in the path are special, they're
changed to the story author and title respectively."""
global dl_semaphore
dl_semaphore = BoundedSemaphore(max_connections)
parse, parse_ch1 = get_parser(main_url)
html_ch1, chapter_num, story_info = get_chapter1(main_url, parse_ch1)
chapters = {}
chapters[1] = html_ch1
if story_info["cover_url"]:
cover_image_req = Request(
story_info["cover_url"], headers=story_info["cover_headers"])
cover_image = urlopen(cover_image_req).read()
else:
cover_image = open("default.jpg", "rb").read()
with concurrent.futures.ThreadPoolExecutor(max_workers=max_connections+3) \
as executor:
parse_chapters = []
download_urls = story_info["chapter_urls"]
for ch in range(2, chapter_num+1):
dl_semaphore.acquire()
parse_chapters.append(
executor.submit(get_chapter, download_urls[ch], ch, parse))
for future in concurrent.futures.as_completed(parse_chapters):
html, chapter_no = future.result()
chapters[chapter_no] = html
if not filepath:
filepath = "{} - {}.epub".format(
INVALID_CHARS.sub("-", story_info["author"]),
INVALID_CHARS.sub("-", story_info["title"]))
else:
filepath = filepath.replace(
"%author", INVALID_CHARS.sub("-", story_info["author"]))
filepath = filepath.replace(
"%title", INVALID_CHARS.sub("-", story_info["title"]))
with zipfile.ZipFile(filepath, "w") as f:
f.writestr("mimetype", MIMETYPE)
f.writestr("META-INF/container.xml", CONTAINER_XML)
f.writestr("Content/titlepage.html", TITLEPAGE_HTML)
f.writestr("Content/styles.css", STYLES_CSS)
f.writestr("Content/cover.jpg", cover_image)
f.writestr("Content/toc.ncx", toc(story_info, chapter_num))
f.writestr("Content/content.opf", contents(story_info, chapter_num))
for ch in range(1, chapter_num+1):
f.writestr("Content/Chapters/ch{}.html".format(ch), chapters[ch])
开发者ID:Morgus,项目名称:ffnet_epub,代码行数:59,代码来源:backend.py
示例3: execute_semaphored_threads
def execute_semaphored_threads():
inputs = list(range(800, 1000))
print("Calculating from {} to {}".format(inputs[0], inputs[-1]))
# only four threads at time
pool_sema = BoundedSemaphore(value=4)
threads = []
for i in inputs:
# limit threads amount
pool_sema.acquire()
t = Thread(target=execute_fib, args=(i,))
threads.append(t)
t.start()
pool_sema.release()
return threads
开发者ID:jsmolina,项目名称:asyncio_course,代码行数:14,代码来源:2ex_threads_fib.py
示例4: __init__
def __init__(self, repos):
self.ui = getglobalui()
self.repos = repos
self.config = repos.getconfig()
self.tunnel = repos.getpreauthtunnel()
self.usessl = repos.getssl()
self.username = repos.getuser()
self.password = None
self.passworderror = None
self.goodpassword = None
self.hostname = repos.gethost()
self.port = repos.getport()
if self.port == None:
self.port = 993 if self.usessl else 143
self.sslclientcert = repos.getsslclientcert()
self.sslclientkey = repos.getsslclientkey()
self.sslcacertfile = repos.getsslcacertfile()
if self.sslcacertfile is None:
self.verifycert = None # disable cert verification
self.delim = None
self.root = None
self.maxconnections = repos.getmaxconnections()
self.availableconnections = []
self.assignedconnections = []
self.lastowner = {}
self.semaphore = BoundedSemaphore(self.maxconnections)
self.connectionlock = Lock()
self.reference = repos.getreference()
self.idlefolders = repos.getidlefolders()
self.gss_step = self.GSS_STATE_STEP
self.gss_vc = None
self.gssapi = False
开发者ID:rayners,项目名称:offlineimap,代码行数:32,代码来源:imapserver.py
示例5: __init__
def __init__(self):
self.__logger = logging.getLogger("framework.facade")
self.mCallBacks = None
self.mutex = BoundedSemaphore(value=1)
self.controller = None
# Messages queue
self.__qmsg = Queue()
self.jman = None
# results storage
self.__results = Results()
# load plugins
self.__logger.info("* Loading plugins")
self.load_plugins()
# load session
self.__logger.info("* Loading session")
self.__cur_session = DataModel()
if Settings().get(Settings.SEC_GRL, Settings.AUTO_SESSION) == 'True':
try:
self.__cur_session = self.load_session()
except Exception:
pass
开发者ID:xmendez,项目名称:misc,代码行数:27,代码来源:facade.py
示例6: __init__
def __init__(self, storage_driver, table_info_repo, concurrent_tasks=1000,
batch_chunk_size=25, schema_operation_timeout=300):
self._storage_driver = storage_driver
self._table_info_repo = table_info_repo
self._batch_chunk_size = batch_chunk_size
self._schema_operation_timeout = schema_operation_timeout
self.__task_executor = ThreadPoolExecutor(concurrent_tasks)
self.__task_semaphore = BoundedSemaphore(concurrent_tasks)
开发者ID:purpen,项目名称:magnetodb,代码行数:8,代码来源:simple_impl.py
示例7: VDOM_semaphore
class VDOM_semaphore(object):
def __init__(self, counter=1):
self.__semaphore = BoundedSemaphore(counter)
def lock(self):
return self.__semaphore.acquire()
def unlock(self):
self.__semaphore.release()
def __enter__(self):
self.lock()
return self
def __exit__(self, extype, exvalue, traceback):
self.unlock()
开发者ID:VDOMBoxGroup,项目名称:runtime2.0,代码行数:17,代码来源:semaphore.py
示例8: __init__
def __init__(self, item_number, person_capacity):
if type(item_number) is not int:
raise Exception("item_number is not an integer")
if type(person_capacity) is not int:
raise Exception("person_capacity is not an integer")
self.item_number = item_number
self.person_capacity = person_capacity
self.sema = BoundedSemaphore(value=self.person_capacity)
开发者ID:mason-fish,项目名称:holbertonschool-higher_level_programming,代码行数:9,代码来源:h_store.py
示例9: __init__
def __init__(self, subscription):
super(Next.Sink, self).__init__(subscription)
self.gate = RLock()
self.semaphore = BoundedSemaphore(1)
self.semaphore.acquire()
self.waiting = False
self.kind = None
self.value = None
self.error = None
开发者ID:aguil,项目名称:RxPython,代码行数:10,代码来源:next.py
示例10: IDCardFactory
class IDCardFactory(Factory):
def __init__(self):
self.owner = []
self.seqNum = 1
self.semaphore = BoundedSemaphore(1)
def createProduct(self, owner):
self.semaphore.acquire()
card = IDCard(self.seqNum, owner)
self.seqNum += 1
self.semaphore.release()
return card
def registerProduct(self, product):
self.owner.append(product.getOwner())
def getOwners(self):
return self.owner
开发者ID:yokoi-h,项目名称:DesignPattern,代码行数:19,代码来源:IDCardFactory.py
示例11: MyThread
class MyThread(threading.Thread):
def __init__(self,site):
self.site = site
threading.Thread.__init__(self)
self.semaphore = BoundedSemaphore(value=MAXCONN)
self.t = Tweetya()
def run(self):
link = self.t.parse(self.site)
self.semaphore.acquire()
urls = self.t.getlinks()
for i in link:
if not (i in urls):
self.t.setlink(i)
short = self.t.short(i)
title = self.t.gettitle(short)
self.t.auth(str(title)+' '+str(short))
self.semaphore.release()
开发者ID:deslum,项目名称:Twittya,代码行数:19,代码来源:Twittya.py
示例12: __init__
def __init__(self, n_process=2, n_threads=5, n_taks=10, daemon=False):
self.daemon = daemon
self.n_taks = n_taks
self.n_threads = n_threads
self.n_process = n_process
self.sem_threads = BoundedSemaphore(self.n_threads)
self.sem_tasks = asyncio.BoundedSemaphore(self.n_taks)
self.running_process = []
开发者ID:cr0hn,项目名称:TestingBench,代码行数:10,代码来源:process_threads_and_tasks_autoscale.py
示例13: __init__
def __init__(self, subscription):
super(Latest.Sink, self).__init__(subscription)
self.gate = RLock()
self.semaphore = BoundedSemaphore(1)
self.semaphore.acquire()
self.notificationAvailable = False
self.kind = None
self.value = None
self.error = None
开发者ID:aguil,项目名称:RxPython,代码行数:10,代码来源:latest.py
示例14: __init__
def __init__(self, dAmn, logging=True, debug=False):
super(Logger, self).__init__()
self.dAmn = dAmn
self.logging = logging
self.mute_channels = []
self.debug = debug
self.running = False
self._run = False
# Create locks
self.qlock = BoundedSemaphore()
#self.mlock = BoundedSemaphore()
self.llock = BoundedSemaphore()
# Create queues
self.wqueue = [] # Output queue
#self.mqueue = [] # Muter queue
self.lqueue = [] # Logger queue. Just in case.
# Just in case.
self.subbing = False
self.subthread = None
开发者ID:photofroggy,项目名称:Terra,代码行数:19,代码来源:console.py
示例15: __init__
def __init__(self, repos):
self.ui = getglobalui()
self.repos = repos
self.config = repos.getconfig()
self.preauth_tunnel = repos.getpreauthtunnel()
self.transport_tunnel = repos.gettransporttunnel()
if self.preauth_tunnel and self.transport_tunnel:
raise OfflineImapError('%s: ' % repos + \
'you must enable precisely one '
'type of tunnel (preauth or transport), '
'not both', OfflineImapError.ERROR.REPO)
self.tunnel = \
self.preauth_tunnel if self.preauth_tunnel \
else self.transport_tunnel
self.username = \
None if self.preauth_tunnel else repos.getuser()
self.user_identity = repos.get_remote_identity()
self.authmechs = repos.get_auth_mechanisms()
self.password = None
self.oauth2 = repos.getoauth2()
self.oauth2url = repos.getoauth2url() if self.oauth2 else None
self.oauth2clientid = repos.getoauth2clientid() if self.oauth2 else None
self.oauth2clientsecret = repos.getoauth2clientsecret() if self.oauth2 else None
self.oauth2refreshtoken = repos.getoauth2refreshtoken() if self.oauth2 else None
self.passworderror = None
self.goodpassword = None
self.usessl = repos.getssl()
self.hostname = \
None if self.preauth_tunnel else repos.gethost()
self.port = repos.getport()
if self.port == None:
self.port = 993 if self.usessl else 143
self.sslclientcert = repos.getsslclientcert()
self.sslclientkey = repos.getsslclientkey()
self.sslcacertfile = repos.getsslcacertfile()
self.sslversion = repos.getsslversion()
if self.sslcacertfile is None:
self.__verifycert = None # disable cert verification
self.delim = None
self.root = None
self.maxconnections = repos.getmaxconnections()
self.availableconnections = []
self.assignedconnections = []
self.lastowner = {}
self.semaphore = BoundedSemaphore(self.maxconnections)
self.connectionlock = Lock()
self.reference = repos.getreference()
self.idlefolders = repos.getidlefolders()
self.gss_step = self.GSS_STATE_STEP
self.gss_vc = None
self.gssapi = False
开发者ID:javiergarmon,项目名称:offlineimap,代码行数:55,代码来源:imapserver.py
示例16: __init__
def __init__(self, device):
self.dev = device
self.sts_semaphore = BoundedSemaphore(value=1)
self.dev.set_configuration()
cfg = self.dev.get_active_configuration()
intf = cfg[(0, 0)]
self.endpoint_out = usb.util.find_descriptor(
intf, custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
self.endpoint_in = usb.util.find_descriptor(
intf, custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
self.cmd = Commands()
# these events are checked by the thread assigned to this device and
# cleared after each one has been serviced
self.update_integ = Event()
self.update_integ.set()
self.update_average_scans = Event()
self.update_average_scans.clear()
self.change_units = Event()
self.change_units.set()
self.data_ready = Event()
self.data_ready.clear()
self.prev_integ = 1
self.dark_integ = 1
self.prev_temp = 0
self.dark_ref_taken = False
self.light_reference = []
self.dark_reference = []
self.x_data = []
self.y_data = []
self.calibration_scan = []
self.dark_pixels = []
self.auto_integration = True
self.avg_scans = 1
self.paired = False
try:
self.read()
except Exception:
pass
self.name = self.get_device_alias()
self.file_path = ''
self.calib_coeff = []
self.wavelength_indices = []
self.irradiance_data = []
self.irrad_unit = 0
self.get_hot_pixel_indices()
self.build_wavelength_indices()
self.get_irradiance_calibration()
# initialized to 10 ms integration period
self.set_integration_period(10000)
开发者ID:gramsejr,项目名称:Spectrovision,代码行数:55,代码来源:USB_Instrument.py
示例17: handle
def handle(self):
self._verified = None
self._apiExists = None
self._success = False # whether the processing has been completed or not
self._request = ''
self._response = ''
self._apicommand = False
self._semaphore = BoundedSemaphore(value=1)
self.cur_thread = None
data = ''
try:
while not (('\n' in data) or ('\r' in data)):
data = data + self.request.recv(1024)
except: #if there is an error while reading, just exit
return
data = data.replace("\b", "")
log_trace('I', '0005', "Request received", detail=data)
self._request = data.strip()+'\n'
#server.queueManager
self.cur_thread = threading.current_thread()
log_trace('D', '0006', "Request received", detail = self.cur_thread.name, data = self._request)
if self._verified is None:
self.testRequest()
if self._verified == False:
if len(self._response) < 6:
log_trace('D', '0007', "Incorrect internal verification response", detail = self.cur_thread.name, data = self._response)
self._response = "ERR204"
self.request.sendall(self._response)
self._semaphore.acquire()
#insert itself to the Queue manager
self.server.queueManager.newRequest(self._request, self.callback)
#block till semaphore is open again
self._semaphore.acquire()
if self._success:
log_trace('D', '0014', "Success - sendall() called", response=self._response)
self.request.sendall(self._response)
elif self._apicommand:
#finally we can do API command processing here
self._response = self.processAPICommand(self._response)
self.request.sendall(self._response)
else:
if len(self._response) < 6:
log_trace('C', '0013', "Incorrect result from request processing", detail=self._response, command=self._request)
self._response = "ERR204"
#TODO call a class constructor and block till its processing is completed
self.request.sendall(self._response)
self._semaphore.release()
开发者ID:smartcrib,项目名称:password-scrambler-ws,代码行数:55,代码来源:scribManager.py
示例18: __init__
def __init__(self, host='chat.deviantart.com', version='dAmnClient 0.3', port=3900, debug=False):
"""Initialise up in this motherfucka"""
Thread.__init__(self)
self.server.host = host
self.server.version = version
self.server.port = port
self.sock = None
self.packet = []
self.__buffer = str()
self._lock = BoundedSemaphore()
self._debug = debug
开发者ID:photofroggy,项目名称:Terra,代码行数:11,代码来源:stream.py
示例19: rpiFIFOClass
class rpiFIFOClass(deque):
"""
Implements the a Deque with BoundedSemaphore.
Used as a FIFO buffer for the image file names (including the full path).
Stores also the name of the current sub-folder.
"""
def __init__(self, *args):
super(rpiFIFOClass,self).__init__(*args)
self.FIFOSema = BoundedSemaphore()
self.crtSubDir = '/'
self.camID = ''
def acquireSemaphore(self):
self.FIFOSema.acquire()
def releaseSemaphore(self):
self.FIFOSema.release()
def __del__(self):
# self.FIFOSema.release()
self.crtSubDir = ''
开发者ID:istvanzk,项目名称:rpicampy,代码行数:21,代码来源:rpififo.py
示例20: __init__
def __init__(self, storage_path=STORAGE_PATH):
self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__))
if not os.path.exists(storage_path):
self.log.debug("Creating directory (%s) for persistent storage" % (storage_path))
os.makedirs(storage_path)
os.chmod(storage_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
elif not os.path.isdir(storage_path):
raise ImageFactoryException("Storage location (%s) already exists and is not a directory - cannot init persistence" % (storage_path))
else:
# TODO: verify that we can write to this location
pass
self.storage_path = storage_path
self.metadata_lock = BoundedSemaphore()
开发者ID:AsherBond,项目名称:imagefactory,代码行数:13,代码来源:FilePersistentImageManager.py
注:本文中的threading.BoundedSemaphore类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论