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

Python posix.close函数代码示例

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

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



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

示例1: do_release

 def do_release(self):
     if self.fd is not None:
         posix.ftruncate(self.fd, 0)
         fcntl.flock(self.fd, fcntl.LOCK_UN)
         posix.close(self.fd)
         self.fd = None
         self._locked = False
开发者ID:HengeSense,项目名称:vesper,代码行数:7,代码来源:glock.py


示例2: test_ignore_ioerror_in_readall_if_nonempty_result

 def test_ignore_ioerror_in_readall_if_nonempty_result(self):
     # this is the behavior of regular files in CPython 2.7, as
     # well as of _io.FileIO at least in CPython 3.3.  This is
     # *not* the behavior of _io.FileIO in CPython 3.4 or 3.5;
     # see CPython's issue #21090.
     import sys
     try:
         from posix import openpty, fdopen, write, close
     except ImportError:
         skip('no openpty on this platform')
     if 'gnukfreebsd' in sys.platform:
         skip('close() hangs forever on kFreeBSD')
     read_fd, write_fd = openpty()
     write(write_fd, 'Abc\n')
     close(write_fd)
     f = fdopen(read_fd)
     # behavior on Linux: f.read() returns 'Abc\r\n', then the next time
     # it raises IOError.  Behavior on OS/X (Python 2.7.5): the close()
     # above threw away the buffer, and f.read() always returns ''.
     if sys.platform.startswith('linux'):
         s = f.read()
         assert s == 'Abc\r\n'
         raises(IOError, f.read)
     else:
         s = f.read()
         assert s == ''
         s = f.read()
         assert s == ''
     f.close()
开发者ID:abhinavthomas,项目名称:pypy,代码行数:29,代码来源:test_file.py


示例3: do_acquire

        def do_acquire(self, waitflag=False):
            locked = False

            if waitflag:
                blockflag = 0
            else:
                blockflag = fcntl.LOCK_NB

            self.fd = posix.open(self.fn, O_CREAT | O_RDWR, 0600)
            try:
                fcntl.flock(self.fd, fcntl.LOCK_EX|blockflag)
                # locked it
                try:
                    posix.ftruncate(self.fd, 0)
                    posix.write(self.fd, `os.getpid()` + '\n')
                    locked = True
                except:
                    self.do_release()
                    raise
            except IOError, x:
                if x.errno == errno.EWOULDBLOCK:
                    # failed to lock
                    posix.close(self.fd)
                    del self.fd
                else:
                    raise
开发者ID:HengeSense,项目名称:vesper,代码行数:26,代码来源:glock.py


示例4: test_rename_at_close_correct_read

 def test_rename_at_close_correct_read(self):
     firstFileFd = posix.open("mount/file1", posix.O_RDONLY)
     secondFileFd = posix.open("mount/file2", posix.O_RDONLY)
     for i in range(1000):
         position = random.randint(0, 10000)
         size = random.randint(1, 10000)
         posix.lseek(firstFileFd,position, 0)
         posix.lseek(secondFileFd, position, 0)
         posix.read(firstFileFd, size)
         posix.read(secondFileFd, size)
     posix.close(firstFileFd)
     posix.close(secondFileFd)
     posix.rename("mount/file2", "mount/file3")
     posix.rename("mount/file1","mount/file2")
     self.assertTrue(open("mount/file2").read()== open("src/file2").read())
开发者ID:shahamran,项目名称:os,代码行数:15,代码来源:homeTest.py


示例5: one_loop

 def one_loop(self):
     ret = True
     for (fd, ev) in self.poller.poll(1000):
         if ev & (select.POLLERR | select.POLLHUP):
             self.flush_outputs()
             self.poller.unregister(fd)
             ret = False
         if ev & select.POLLIN:
             data = posix.read(fd, 4096)
             if not data:
                 posix.close(self.fd_map[fd])
                 ret = False
             self.queue_write(self.fd_map[fd], data)
         if ev & select.POLLOUT:
             self.do_write(fd)
     return ret
开发者ID:JD-Multimedia,项目名称:gandi.cli,代码行数:16,代码来源:unixpipe.py


示例6: make_tempfile

    def make_tempfile(fn, pid):
        tfn = os.path.join(os.path.dirname(fn), 'shlock%d.tmp' % pid)

        errcount = 1000
        while 1:
            try:
                fd = posix.open(tfn, O_EXCL | O_CREAT | O_RDWR, 0600)
                posix.write(fd, '%d\n' % pid)
                posix.close(fd)

                return tfn
            except OSError, x:
                if (errcount > 0) and (x.errno == errno.EEXIST):
                    os.unlink(tfn)
                    errcount = errcount - 1
                else:
                    raise
开发者ID:HengeSense,项目名称:vesper,代码行数:17,代码来源:glock.py


示例7: test_ignore_ioerror_in_readall_if_nonempty_result

 def test_ignore_ioerror_in_readall_if_nonempty_result(self):
     # this is the behavior of regular files in CPython 2.7, as
     # well as of _io.FileIO at least in CPython 3.3.  This is
     # *not* the behavior of _io.FileIO in CPython 3.4 or 3.5;
     # see CPython's issue #21090.
     try:
         from posix import openpty, fdopen, write, close
     except ImportError:
         skip('no openpty on this platform')
     read_fd, write_fd = openpty()
     write(write_fd, 'Abc\n')
     close(write_fd)
     f = fdopen(read_fd)
     s = f.read()
     assert s == 'Abc\r\n'
     raises(IOError, f.read)
     f.close()
开发者ID:bukzor,项目名称:pypy,代码行数:17,代码来源:test_file.py


示例8: jog_i2c_write

def jog_i2c_write(addr, register, value, debug):
    import fcntl
    import posix

    n_i2c = 0
    f_i2c = posix.open("/dev/i2c-%i" % n_i2c, posix.O_RDWR)

    flags = I2C_M_WR
    buf = ctypes.create_string_buffer(2)
    buf[0] = chr(register)
    buf[1] = chr(value)
    msgs = I2cMsg(addr=addr, flags=flags, len=ctypes.sizeof(buf), buf=buf)
    msg_array, msg_count = i2c_ioctl_msg(msgs)
    io_i2c = I2cRdwrIoctlData(msgs=msg_array, nmsgs=msg_count)
    i2c_stat = fcntl.ioctl(f_i2c, I2C_RDWR, io_i2c)

    posix.close(f_i2c)
开发者ID:adrien-bellaiche,项目名称:Interceptor,代码行数:17,代码来源:jogio_utils.py


示例9: test_rename_folder_correct_read

    def test_rename_folder_correct_read(self):
        os.mkdir("src/folder1")
        os.mkdir("src/folder2")
        os.system("cp src/file1 src/folder1/file") 
        os.system("cp src/file2 src/folder2/file") 


        firstFileFd = posix.open("mount/folder1/file", posix.O_RDONLY)
        secondFileFd = posix.open("mount/folder2/file", posix.O_RDONLY)
        for i in range(1000):
            position = random.randint(0, 10000)
            size = random.randint(1, 10000)
            posix.lseek(firstFileFd,position, 0)
            posix.lseek(secondFileFd, position, 0)
            posix.read(firstFileFd, size)
            posix.read(secondFileFd, size)
        posix.rename("mount/folder2", "mount/folder3")
        posix.rename("mount/folder1","mount/folder2")
        posix.close(firstFileFd)
        posix.close(secondFileFd)
        self.assertTrue(open("mount/folder2/file").read()== open("src/folder2/file").read())
开发者ID:shahamran,项目名称:os,代码行数:21,代码来源:homeTest.py


示例10: test_randomAccessToFile

 def test_randomAccessToFile(self):
     position = 0
     size = 0
     srcFileFd = posix.open("src/file1", posix.O_RDONLY)
     mountFileFd = posix.open("mount/file1", posix.O_RDONLY)
     for i in range(10000):
         position = random.randint(0, 10000)
         size = random.randint(1, 10000)
         posix.lseek(srcFileFd,position, 0)
         posix.lseek(mountFileFd, position, 0)
         if (posix.read(srcFileFd,size) !=  posix.read(mountFileFd, size)):
             posix.close(srcFileFd)
             posix.close(mountFileFd)
             self.assertTrue(False)
     posix.close(srcFileFd)
     posix.close(mountFileFd)
开发者ID:shahamran,项目名称:os,代码行数:16,代码来源:homeTest.py


示例11: daemonize

def daemonize(logfile):
    try:
        from os import fork
        from posix import close
    except:
        print 'Daemon mode is not supported on this platform (missing fork() syscall or posix module)'
        sys_exit(-1)

    import sys
    if (fork()): sys_exit(0) # parent return to shell

    ### Child
    close(sys.stdin.fileno())
    sys.stdin  = open('/dev/null')
    close(sys.stdout.fileno())
    sys.stdout = Log(open(logfile, 'a+'))
    close(sys.stderr.fileno())
    sys.stderr = Log(open(logfile, 'a+'))
    chdir('/')
开发者ID:blueardour,项目名称:pxe-server,代码行数:19,代码来源:binlsrv.py


示例12: close

 def close(self):
     """
     Closes the I2C bus device.
     """
     posix.close(self.fd)
开发者ID:Jemgoss,项目名称:quick2wire-python-api,代码行数:5,代码来源:i2c.py


示例13: __del__

 def __del__(self):
     try:
         posix.close(self.fd)
     except AttributeError:
         pass #Do nothing in this case.
开发者ID:HappyFox,项目名称:Python-i2c,代码行数:5,代码来源:__init__.py


示例14: close

 def close(self):
     """
     Closes the file descriptor.
     """
     posix.close(self.fd)
开发者ID:HubCityLabs,项目名称:hikaru-gatekeeper,代码行数:5,代码来源:spi.py


示例15: close

 def close(self):
     """Closes the SPI device file descriptor."""
     posix.close(self.fd)
     self.fd = None
开发者ID:RobbieClarken,项目名称:python3-microstackcommon,代码行数:4,代码来源:spi.py


示例16: test_dont_close_fd_if_dir_check_fails_in_fdopen

 def test_dont_close_fd_if_dir_check_fails_in_fdopen(self):
     import posix
     fd = posix.open('/', posix.O_RDONLY)
     raises(IOError, posix.fdopen, fd)
     posix.close(fd)
开发者ID:mozillazg,项目名称:pypy,代码行数:5,代码来源:test_file_extra.py


示例17: deinit

def deinit():
    """Closes the SPI device file descriptor."""
    global spidev_fd
    if spidev_fd:
        posix.close(spidev_fd)
    spidev_fd = None
开发者ID:gevision,项目名称:pifacecommon,代码行数:6,代码来源:core.py


示例18: close_fd

 def close_fd(self):
     posix.close(self.fd)
     del self.fd
开发者ID:mpruessmeier,项目名称:pifacecommon,代码行数:3,代码来源:spi.py


示例19: close_fd

 def close_fd(self):
     posix.close(self.fd)
     self.fd = None
开发者ID:erlengra,项目名称:pifacecommon,代码行数:3,代码来源:spi.py


示例20: close

	def close(self):
		dummy = posix.close(self.fd)
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:2,代码来源:VCR.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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