• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python msvcrt.locking函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msvcrt.locking函数的典型用法代码示例。如果您正苦于以下问题:Python locking函数的具体用法?Python locking怎么用?Python locking使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了locking函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _flock

	def _flock(fp):
		# The string representation of a PID should never be
		# bigger than 32 characters, not even on 64bit systems.
		# However, it should work even if it is, because all
		# FileLocks want to lock the same proportion of the
		# file, even though it might not be the whole file.
		locking(fp.fileno(), LK_LOCK, 32)
开发者ID:fracture91,项目名称:Message,代码行数:7,代码来源:locklib.py


示例2: _remove_lock

 def _remove_lock(self):
     if sys.platform == 'win32':
         import msvcrt
         msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_UNLCK, 32)
     else:
         import fcntl
         fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_UN)
开发者ID:3163504123,项目名称:phantomjs,代码行数:7,代码来源:file_lock.py


示例3: _create_lock

 def _create_lock(self):
     if sys.platform == 'win32':
         import msvcrt
         msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_NBLCK, 32)
     else:
         import fcntl
         fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
开发者ID:3163504123,项目名称:phantomjs,代码行数:7,代码来源:file_lock.py


示例4: _remove_lock

 def _remove_lock(self):
     if sys.platform in ('darwin', 'linux2', 'cygwin'):
         import fcntl
         fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_UN)
     elif sys.platform == 'win32':
         import msvcrt
         msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_UNLCK, 32)
开发者ID:achellies,项目名称:WinCEWebKit,代码行数:7,代码来源:file_lock.py


示例5: __enter__

    def __enter__(self):

        try:
            self.fd = os.open(self.name, os.O_WRONLY | os.O_CREAT | os.O_APPEND)
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise LockFileCreationException(e)
            else:
                raise
        self.file = os.fdopen(self.fd, "w")
        if is_windows:
            lock_flags = msvcrt.LK_LOCK
        else:
            lock_flags = fcntl.LOCK_EX
        if self.fail_on_lock:
            if is_windows:
                lock_flags = msvcrt.LK_NBLCK
            else:
                lock_flags |= fcntl.LOCK_NB
        try:
            if is_windows:
                msvcrt.locking(self.file.fileno(), lock_flags, 1)
            else:
                fcntl.flock(self.file, lock_flags)
        except IOError as e:
            error_code = errno.EACCES if is_windows else errno.EAGAIN
            if e.errno == error_code:
                raise LockFileObtainException()
            raise

        return self.file
开发者ID:AbletonAG,项目名称:abl.util,代码行数:31,代码来源:lockfile.py


示例6: _lock_file_non_blocking

 def _lock_file_non_blocking(file_):
     try:
         msvcrt.locking(file_.fileno(), msvcrt.LK_NBLCK, 1)
         return True
     # TODO: check errno
     except IOError:
         return False
开发者ID:mrocklin,项目名称:locket.py,代码行数:7,代码来源:__init__.py


示例7: unlock_file

def unlock_file(fd):
	try:
		import msvcrt
		msvcrt.locking(fd, 0, 1024)
	except ImportError:
		pass
	os.close(fd)
开发者ID:dieterdeyke,项目名称:WAMPES,代码行数:7,代码来源:bbs.py


示例8: _lock_windows

 def _lock_windows(self):
     try:
         msvcrt.locking(self.fh, msvcrt.LK_LOCK, 1)
     except OSError:
         return False
     else:
         return True
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:7,代码来源:hifi_singleton.py


示例9: _lock_file

 def _lock_file(self, name, f):
     import msvcrt
     for p in range(0,
                    min(self.sizes[name], MAXLOCKRANGE), MAXLOCKSIZE):
         f.seek(p)
         msvcrt.locking(f.fileno(), msvcrt.LK_LOCK,
                        min(MAXLOCKSIZE, self.sizes[name] - p))
开发者ID:Konubinix,项目名称:BitTornado,代码行数:7,代码来源:Storage.py


示例10: do_acquire

        def do_acquire(self, waitflag=False):            
            if waitflag:
                sleep = 1
                locked = self.do_acquire(False)

                while not locked:
                    time.sleep(sleep)
                    sleep = min(sleep + 1, 15)
                    locked = self.do_acquire(False)
                return locked

            locked = False

            self.f = open(self.fn, 'a')
            try:
                msvcrt.locking(self.f.fileno(), msvcrt.LK_NBLCK, 1)
                try:
                    self.f.write(`os.getpid()` + '\n')  # informational only
                    self.f.seek(0)  # lock is at offset 0, so go back there
                    locked = True
                except:
                    self.do_release()
                    raise

            except IOError, x:
                if x.errno == errno.EACCES:
                    self.f.close()
                    del self.f
                else:
                    raise
开发者ID:HengeSense,项目名称:vesper,代码行数:30,代码来源:glock.py


示例11: _tryflock

	def _tryflock(fp):
		try:
			locking(fp.fileno(), LK_LOCK | LK_NBLCK, 32)
		except IOError:
			return False
		else:
			return True
开发者ID:fracture91,项目名称:Message,代码行数:7,代码来源:locklib.py


示例12: __release_lock

def __release_lock(lock):
  if sys.platform == "win32":
    import msvcrt
    msvcrt.locking(lock.fileno(), msvcrt.LK_UNLCK, 1)
  else:
    import fcntl
    fcntl.flock(lock, fcntl.LOCK_UN)
开发者ID:FedoraScientific,项目名称:salome-kernel,代码行数:7,代码来源:PortManager.py


示例13: _create_lock

 def _create_lock(self):
     if sys.platform.startswith('linux') or sys.platform in ('darwin', 'cygwin'):
         import fcntl
         fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
     elif sys.platform == 'win32':
         import msvcrt
         msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_NBLCK, 32)
开发者ID:mrragava,项目名称:os-design,代码行数:7,代码来源:file_lock.py


示例14: create_extension

    def create_extension(self, code, force=False, name=None,
                         include_dirs=None,
                         library_dirs=None,
                         runtime_library_dirs=None,
                         extra_compile_args=None,
                         extra_link_args=None,
                         libraries=None,
                         compiler=None,
                         ):

        if Cython is None:
            raise ImportError('Cython is not available')

        code = deindent(code)

        lib_dir = os.path.expanduser('~/.brian/cython_extensions')
        try:
            os.makedirs(lib_dir)
        except OSError:
            if not os.path.exists(lib_dir):
                raise

        key = code, sys.version_info, sys.executable, Cython.__version__
            
        if force:
            # Force a new module name by adding the current time to the
            # key which is hashed to determine the module name.
            key += time.time(),            

        if key in self._code_cache:
            return self._code_cache[key]

        if name is not None:
            module_name = name#py3compat.unicode_to_str(args.name)
        else:
            module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()



        module_path = os.path.join(lib_dir, module_name + self.so_ext)

        if prefs['codegen.runtime.cython.multiprocess_safe']:
            lock_file = os.path.join(lib_dir, module_name + '.lock')
            with open(lock_file, 'w') as f:
                if msvcrt:
                    msvcrt.locking(f.fileno(), msvcrt.LK_RLCK,
                                   os.stat(lock_file).st_size)
                else:
                    fcntl.flock(f, fcntl.LOCK_EX)
                return self._load_module(module_path, include_dirs,
                                         library_dirs,
                                         extra_compile_args, extra_link_args,
                                         libraries, code, lib_dir, module_name,
                                         runtime_library_dirs, compiler, key)
        else:
            return self._load_module(module_path, include_dirs, library_dirs,
                                     extra_compile_args, extra_link_args,
                                     libraries, code, lib_dir, module_name,
                                     runtime_library_dirs, compiler, key)
开发者ID:SudShekhar,项目名称:brian2,代码行数:59,代码来源:extension_manager.py


示例15: lockf

 def lockf(fileno,mode):
     if mode & LOCK_UN:
         msvcrt.locking(fileno, msvcrt.LK_UNLCK, 0)
     if mode & _locks:
         msmode = _modes[mode & _locks]
         if msmode is None:
             raise AssertionError("Invalid lock flags", mode)
         msvcrt.locking(fileno, msmode, 0)
开发者ID:HackLinux,项目名称:chandler-1,代码行数:8,代码来源:lock.py


示例16: unlock2

def unlock2(fd):
    if sys.platform == "win32":
        os.lseek(fd, 0, 0)  # make sure we're at the beginning
        msvcrt.locking(fd, msvcrt.LK_UNLCK, 10) # assuming first 10 bytes!
    else:
        fcntl.flock(fd, fcntl.LOCK_UN)

    return
开发者ID:mikegr,项目名称:lectorious-grails-qooxdoo,代码行数:8,代码来源:filetool.py


示例17: write

def write():
    try:
        fd = open( ini_filename, "w" )
        msvcrt.locking( fd.fileno(), msvcrt.LK_LOCK, 1 )
        ini.write(fd)
        fd.close()
    except:
        pass
开发者ID:crftwr,项目名称:keyhac,代码行数:8,代码来源:keyhac_ini.py


示例18: __acquire_lock

def __acquire_lock(lock):
  if sys.platform == "win32":
    import msvcrt
    # lock 1 byte: file is supposed to be zero-byte long
    msvcrt.locking(lock.fileno(), msvcrt.LK_LOCK, 1)
  else:
    import fcntl
    fcntl.flock(lock, fcntl.LOCK_EX)
开发者ID:FedoraScientific,项目名称:salome-kernel,代码行数:8,代码来源:PortManager.py


示例19: release

    def release(self):
        import msvcrt  # @UnresolvedImport

        if self.fd is None:
            raise Exception("Lock was not acquired")
        msvcrt.locking(self.fd, msvcrt.LK_UNLCK, 1)
        os.close(self.fd)
        self.fd = None
开发者ID:Code-Alliance-Archive,项目名称:oh-mainline,代码行数:8,代码来源:filelock.py


示例20: unlock

 def unlock(file):
     """
     Unlock first 10 bytes of a file.
     """
     pos = file.tell() # remember current position
     file.seek(0)
     msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
     file.seek(pos) # reset position
开发者ID:Burney222,项目名称:Master-Make-Based,代码行数:8,代码来源:locker.py



注:本文中的msvcrt.locking函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msvcrt.open_osfhandle函数代码示例发布时间:2022-05-27
下一篇:
Python msvcrt.kbhit函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap