当前位置: 首页>>代码示例>>Python>>正文


Python msvcrt.locking函数代码示例

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


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


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