本文整理汇总了Python中portalocker.unlock函数的典型用法代码示例。如果您正苦于以下问题:Python unlock函数的具体用法?Python unlock怎么用?Python unlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, request, folder=None):
self.request = request
# Lets test if the cache folder exists, if not
# we are going to create it
folder = folder or os.path.join(request.folder, "cache")
if not os.path.exists(folder):
os.mkdir(folder)
### we need this because of a possible bug in shelve that may
### or may not lock
self.locker_name = os.path.join(request.folder, "cache/cache.lock")
self.shelve_name = os.path.join(request.folder, "cache/cache.shelve")
locker, locker_locked = None, False
try:
locker = open(self.locker_name, "a")
portalocker.lock(locker, portalocker.LOCK_EX)
locker_locked = True
storage = shelve.open(self.shelve_name)
if not storage.has_key(CacheAbstract.cache_stats_name):
storage[CacheAbstract.cache_stats_name] = {"hit_total": 0, "misses": 0}
storage.sync()
except ImportError:
pass # no module _bsddb, ignoring exception now so it makes a ticket only if used
except:
logger.error("corrupted file: %s" % self.shelve_name)
if locker_locked:
portalocker.unlock(locker)
if locker:
locker.close()
开发者ID:bboilerr,项目名称:onthefattrack,代码行数:33,代码来源:cache.py
示例2: findT
def findT(path, language='en-us'):
"""
must be run by the admin app
"""
filename = os.path.join(path, 'languages', '%s.py' % language)
sentences = read_dict(filename)
mp = os.path.join(path, 'models')
cp = os.path.join(path, 'controllers')
vp = os.path.join(path, 'views')
for file in listdir(mp, '.+\.py', 0) + listdir(cp, '.+\.py', 0)\
+ listdir(vp, '.+\.html', 0):
fp = open(file, 'r')
portalocker.lock(fp, portalocker.LOCK_SH)
data = fp.read()
portalocker.unlock(fp)
fp.close()
items = regex_translate.findall(data)
for item in items:
try:
message = eval(item)
if not message.startswith('#') and not '\n' in message:
tokens = message.rsplit('##', 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
message = tokens[0].strip() + '##' + tokens[1].strip()
if message and not message in sentences:
sentences[message] = message
except:
pass
write_dict(filename, sentences)
开发者ID:PedroVenancio,项目名称:aula5_jan12,代码行数:32,代码来源:languages.py
示例3: findT
def findT(path, language="en-us"):
"""
must be run by the admin app
"""
filename = os.path.join(path, "languages", "%s.py" % language)
sentences = read_dict(filename)
mp = os.path.join(path, "models")
cp = os.path.join(path, "controllers")
vp = os.path.join(path, "views")
for file in listdir(mp, ".+\.py", 0) + listdir(cp, ".+\.py", 0) + listdir(vp, ".+\.html", 0):
fp = open(file, "r")
portalocker.lock(fp, portalocker.LOCK_SH)
data = fp.read()
portalocker.unlock(fp)
fp.close()
items = regex_translate.findall(data)
for item in items:
try:
message = eval(item)
if not message.startswith("#") and not "\n" in message:
tokens = message.rsplit("##", 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
message = tokens[0].strip() + "##" + tokens[1].strip()
if message and not message in sentences:
sentences[message] = message
except:
pass
write_dict(filename, sentences)
开发者ID:bboilerr,项目名称:onthefattrack,代码行数:31,代码来源:languages.py
示例4: planet
def planet():
#return ""
import gluon.contrib.rss2 as rss2
# store planet rss entries in disk (forever...)
import portalocker
import os, cPickle as pickle
path = os.path.join(request.folder,'cache', "planet.rss")
if not os.path.exists(path):
f = open(path, "w+")
rss = get_planet_rss(None)
rss = [{'title': item.title, 'author': item.author, 'pubDate': item.pubDate, 'link': item.link, 'description': item.description} for item in rss.items]
else:
f = open(path, "r+")
rss = None
portalocker.lock(f, portalocker.LOCK_EX)
if not rss:
rss = pickle.load(f)
else:
f.seek(0)
pickle.dump(rss, f)
portalocker.unlock(f)
f.close()
# .rss requests
if request.extension == "rss":
# return new rss feed xml
response.headers['Content-Type']='application/rss+xml'
return rss2.dumps(rss)
# else send the rss object to be processed by
# the view
return response.render(dict(rss = rss, rss2 = rss2))
开发者ID:reingart,项目名称:web2conf,代码行数:34,代码来源:default_fix.py
示例5: load_storage
def load_storage(filename):
fp = open(filename, 'rb')
portalocker.lock(fp, portalocker.LOCK_EX)
storage = cPickle.load(fp)
portalocker.unlock(fp)
fp.close()
return Storage(storage)
开发者ID:BlackgateResearch,项目名称:gmr,代码行数:7,代码来源:storage.py
示例6: unlock
def unlock(self,key):
try: portalocker.unlock(self.locked[key])
except: print "Cache error unlocking file with key " + key
try: self.locked[key].close()
except: print "Cache error closing file with key " + key
del self.open[key]
del self.locked[key]
开发者ID:h3idan,项目名称:vboxweb,代码行数:7,代码来源:cache.py
示例7: __getCachedData
def __getCachedData(self,key):
fname = self.__fname(key)
# Pre-existing locked read
if(self.locked.get(key)):
self.locked[key].seek(0)
try: str = pickle.load(self.locked[key])
except: str = False
self.locked[key].seek(0)
return str
fp=open(fname, "r")
self.open[key] = fp
portalocker.lock(fp,portalocker.LOCK_SH)
# The following 2 lines handle cases where open (above) was called
# on an empty file that was created by cache::lock()
fp.seek(0)
try: str = pickle.load(fp)
except: str = False
try: portalocker.unlock(fp)
except: print "Cache error unlocking file with key " + key
try: fp.close()
except: print "Cache error closing file with key " + key
del self.open[key]
return str
开发者ID:h3idan,项目名称:vboxweb,代码行数:31,代码来源:cache.py
示例8: _open_shelve_and_lock
def _open_shelve_and_lock(self):
"""Open and return a shelf object, obtaining an exclusive lock
on self.locker first. Replaces the close method of the
returned shelf instance with one that releases the lock upon
closing."""
storage = None
locker = None
locked = False
try:
locker = locker = open(self.locker_name, 'a')
portalocker.lock(locker, portalocker.LOCK_EX)
locked = True
try:
storage = shelve.open(self.shelve_name)
except:
logger.error('corrupted cache file %s, will try rebuild it' \
% (self.shelve_name))
storage = None
if not storage and os.path.exists(self.shelve_name):
os.unlink(self.shelve_name)
storage = shelve.open(self.shelve_name)
if not CacheAbstract.cache_stats_name in storage.keys():
storage[CacheAbstract.cache_stats_name] = {'hit_total':0, 'misses': 0}
storage.sync()
except Exception, e:
if storage:
storage.close()
storage = None
if locked:
portalocker.unlock(locker)
locker.close()
locked = False
raise RuntimeError, 'unable to create/re-create cache file %s' % self.shelve_name
开发者ID:kingiol,项目名称:web2py,代码行数:34,代码来源:cache.py
示例9: myunlock
def myunlock(myfilename):
lock_file = portalock_open(myfilename)
lock_file.truncate()
lock_file.write('clear\n')
lock_file.flush()
portalocker.unlock(lock_file)
lock_file.close()
开发者ID:MogeiWang,项目名称:olfactory-bulb,代码行数:7,代码来源:lock_utils.py
示例10: __call__
def __call__(
self,
key,
f,
time_expire = DEFAULT_TIME_EXPIRE,
):
dt = time_expire
locker = open(self.locker_name,'a')
portalocker.lock(locker, portalocker.LOCK_EX)
storage = shelve.open(self.shelve_name)
item = storage.get(key, None)
if item and f == None:
del storage[key]
portalocker.unlock(locker)
locker.close()
if f is None:
return None
if item and (dt == None or item[0] > time.time() - dt):
return item[1]
value = f()
locker = open(self.locker_name,'a')
portalocker.lock(locker, portalocker.LOCK_EX)
storage[key] = (time.time(), value)
storage.sync()
portalocker.unlock(locker)
locker.close()
return value
开发者ID:molhokwai,项目名称:pypress4gae,代码行数:27,代码来源:cache.py
示例11: findT
def findT(path, language='en-us'):
"""
must be run by the admin app
"""
filename = os.path.join(path, 'languages', '%s.py' % language)
sentences = read_dict(filename)
mp = os.path.join(path, 'models')
cp = os.path.join(path, 'controllers')
vp = os.path.join(path, 'views')
for file in listdir(mp, '.+\.py', 0) + listdir(cp, '.+\.py', 0)\
+ listdir(vp, '.+\.html', 0):
fp = open(file, 'r')
portalocker.lock(fp, portalocker.LOCK_SH)
data = fp.read()
portalocker.unlock(fp)
fp.close()
items = regex_translate.findall(data)
for item in items:
try:
msg = eval(item)
if msg and not msg in sentences:
sentences[msg] = msg
except:
pass
write_dict(filename, sentences)
开发者ID:ramanan12345,项目名称:fog-web2py,代码行数:25,代码来源:languages.py
示例12: test_simple
def test_simple():
fh = open('tests/test_file.txt', 'r+')
portalocker.lock(fh, portalocker.LOCK_EX)
fh.seek(12)
fh.write('foo')
portalocker.unlock(fh)
fh.close()
开发者ID:Backblaze,项目名称:portalocker,代码行数:7,代码来源:tests.py
示例13: from_conf
def from_conf(cls, path=None, **overrides):
'''Initialize instance from YAML configuration file,
writing updates (only to keys, specified by "conf_update_keys") back to it.'''
import yaml
if path is None:
path = cls.conf_path_default
log.debug('Using default state-file path: {}'.format(path))
path = os.path.expanduser(path)
with open(path, 'r') as src:
portalocker.lock(src, portalocker.LOCK_SH)
# fcntl.lockf(src, fcntl.LOCK_SH)
conf = yaml.load(src.read())
portalocker.unlock(src)
conf.setdefault('conf_save', path)
conf_cls = dict()
for ns, keys in cls.conf_update_keys.viewitems():
for k in keys:
try:
v = conf.get(ns, dict()).get(k)
except AttributeError:
if not cls.conf_raise_structure_errors: raise
raise KeyError('Unable to get value for configuration parameter'
' "{k}" in section "{ns}", check configuration file (path: {path}) syntax'
' near the aforementioned section/value.'.format(ns=ns, k=k, path=path))
if v is not None:
conf_cls['{}_{}'.format(ns, k)] = conf[ns][k]
conf_cls.update(overrides)
self = cls(**conf_cls)
self.conf_save = conf['conf_save']
return self
开发者ID:AntonioChen,项目名称:python-skydrive,代码行数:33,代码来源:conf.py
示例14: _unlock
def _unlock(self):
response = current.response
if response and getattr(response,'session_file',None) and getattr(response,'session_locked',None):
try:
portalocker.unlock(response.session_file)
response.session_locked = False
except: # this should never happen but happens in Windows
pass
开发者ID:Salmista-94,项目名称:web3py,代码行数:8,代码来源:session.py
示例15: progress_bar
def progress_bar(current, left):
with open('progress_bar.lock', 'w') as lockfile:
portalocker.lock(lockfile, portalocker.LOCK_EX)
progress = 120 * (current/left)
stringbuilder = '[{0}] {1}%'.format('#' * (progress / 12), progress * 120 * 100)
lockfile.write(stringbuilder)
say(stringbuilder)
portalocker.unlock(lockfile)
开发者ID:wikiteams,项目名称:emergent-task-allocation,代码行数:8,代码来源:scream.py
示例16: _unlock
def _unlock(self, response):
if response and response.session_file:
try:
portalocker.unlock(response.session_file)
response.session_file.close()
del response.session_file
except: ### this should never happen but happens in Windows
pass
开发者ID:ramanan12345,项目名称:fog-web2py,代码行数:8,代码来源:globals.py
示例17: save_storage
def save_storage(storage, filename):
fp = open(filename, 'wb')
try:
portalocker.lock(fp, portalocker.LOCK_EX)
cPickle.dump(dict(storage), fp)
portalocker.unlock(fp)
finally:
fp.close()
开发者ID:chrischeyne,项目名称:Cassandra-Monitor,代码行数:8,代码来源:storage.py
示例18: write_dict
def write_dict(filename, contents):
fp = open(filename, 'w')
portalocker.lock(fp, portalocker.LOCK_EX)
fp.write('{\n')
for key in sorted(contents):
fp.write('%s: %s,\n' % (repr(key), repr(contents[key])))
fp.write('}\n')
portalocker.unlock(fp)
fp.close()
开发者ID:ramanan12345,项目名称:fog-web2py,代码行数:9,代码来源:languages.py
示例19: read_dict
def read_dict(filename):
fp = open(filename, 'r')
portalocker.lock(fp, portalocker.LOCK_SH)
lang_text = fp.read().replace('\r\n', '\n')
portalocker.unlock(fp)
fp.close()
if not lang_text.strip():
return {}
return eval(lang_text)
开发者ID:ramanan12345,项目名称:fog-web2py,代码行数:9,代码来源:languages.py
示例20: _close_shelve_and_unlock
def _close_shelve_and_unlock(self):
try:
if self.storage:
self.storage.close()
finally:
if self.locker and self.locked:
portalocker.unlock(self.locker)
self.locker.close()
self.locked = False
开发者ID:apopx,项目名称:web2py,代码行数:9,代码来源:cache.py
注:本文中的portalocker.unlock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论