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

Python fdesc.setNonBlocking函数代码示例

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

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



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

示例1: __init__

    def __init__(self, fp, callback):
        self.fp = fp
        fdesc.setNonBlocking(fp)
        self.callback = callback
        self.fileno = self.fp.fileno

        abstract.FileDescriptor.__init__(self, reactor)
开发者ID:Duologic,项目名称:python-deployer,代码行数:7,代码来源:telnet_server.py


示例2: _dump_file

    def _dump_file(self, file, submission_gus, file_gus):

        result = {}
        result['file_gus'] = file_gus
        result['name'] = file['filename']
        result['type'] = file['content_type']
        result['size'] = len(file['body'])

        # XXX verify this token what's is it
        result['token'] = submission_gus

        if not os.path.isdir(config.advanced.submissions_dir):
            print "%s does not exist. Creating it." % config.advanced.submissions_dir
            os.mkdir(config.advanced.submissions_dir)

        the_submission_dir = config.advanced.submissions_dir

        # this happen only at the first execution
        if not os.path.isdir(the_submission_dir):
            os.mkdir(the_submission_dir)

        filelocation = os.path.join(the_submission_dir, file_gus)

        print "Saving file \"%s\" of %d byte [%s] type, to %s" % \
              (result['name'], result['size'], result['type'], filelocation )

        with open(filelocation, 'w+') as fd:
            fdesc.setNonBlocking(fd.fileno())
            fdesc.writeToFD(fd.fileno(), file['body'])

        return result
开发者ID:hellais,项目名称:GLBackend,代码行数:31,代码来源:fileoperations.py


示例3: setUp

 def setUp(self):
     """
     Create a non-blocking pipe that can be used in tests.
     """
     self.r, self.w = os.pipe()
     fdesc.setNonBlocking(self.r)
     fdesc.setNonBlocking(self.w)
开发者ID:AmirKhooj,项目名称:VTK,代码行数:7,代码来源:test_fdesc.py


示例4: __init__

    def __init__(self, reactor, proc, name, fileno, forceReadHack=False):
        """
        Initialize, specifying a Process instance to connect to.
        """
        abstract.FileDescriptor.__init__(self, reactor)
        fdesc.setNonBlocking(fileno)
        self.proc = proc
        self.name = name
        self.fd = fileno

        if forceReadHack:
            self.enableReadHack = True
        else:
            # Detect if this fd is actually a write-only fd. If it's
            # valid to read, don't try to detect closing via read.
            # This really only means that we cannot detect a TTY's write
            # pipe being closed.
            try:
                os.read(self.fileno(), 0)
            except OSError:
                # It's a write-only pipe end, enable hack
                self.enableReadHack = True

        if self.enableReadHack:
            self.startReading()
开发者ID:axray,项目名称:dataware.dreamplug,代码行数:25,代码来源:process.py


示例5: __init__

 def __init__(self, trigger, fname, mode):
     super(FD, self).__init__()
     self.trigger = trigger
     self._init_fp(fname, mode)
     fdesc.setNonBlocking(self)
     self.connected = True  # Required by FileDescriptor class
     self.data = b""
开发者ID:JvanDalfsen,项目名称:calvin-base,代码行数:7,代码来源:filedescriptor.py


示例6: run

    def run(self, cd_path=None, action_name=None, parameters=None):
        """
        Run main event loop.
        """
        # Set stdin non blocking and raw
        fdesc.setNonBlocking(sys.stdin)
        tcattr = termios.tcgetattr(sys.stdin.fileno())
        tty.setraw(sys.stdin.fileno())

        # Report size
        self._send_size()

        self.socket.sendall(pickle.dumps(('_start-interaction', {
                'cd_path': cd_path,
                'action_name': action_name,
                'parameters': parameters,
            })))

        self._read_loop()

        # Reset terminal state
        termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, tcattr)

        # Put the cursor again at the left margin.
        sys.stdout.write('\r\n')

        # Set exit status
        sys.exit(self.exit_status)
开发者ID:janfabry,项目名称:python-deployer,代码行数:28,代码来源:socket_client.py


示例7: updateReport

 def updateReport(self, report_filename, data):
     try:
         with open(report_filename, 'a+') as fd:
             fdesc.setNonBlocking(fd.fileno())
             fdesc.writeToFD(fd.fileno(), data)
     except IOError as e:
         e.OONIBError(404, "Report not found")
开发者ID:not-the-nsa,项目名称:ooni-backend,代码行数:7,代码来源:handlers.py


示例8: open

 def open(self):
     self.nflog_handle = call_nf(nflog_open, error=0)
     self.nfnl_handle = call_nf(nflog_nfnlh, self.nflog_handle, error=0)
     self.fd = nflog_fd(self.nflog_handle)
     if self.non_blocking:
         # set the fd non blocking so we can use nfnl_catch to do the processing
         fdesc.setNonBlocking(self.fd)
开发者ID:alessandrod,项目名称:cattivo,代码行数:7,代码来源:wrapper.py


示例9: startService

 def startService(self):
     """docstring for startService"""
     log.msg("Starting %s" % self)
     self.filename = self.getFileName()
     def checkAndMove(filename,offset=0):
         if os.path.isfile(self._outfileName) and offset <= self.keepFiles:
             offset += 1
             newFileName = self.outdir + os.path.sep + os.path.basename(self.filename[:-(len(self.suffix))]) + '.%s%s' % (offset,self.suffix)
             checkAndMove(newFileName,offset)
             if os.path.isfile(filename):
                 shutil.move(filename,newFileName)
             
     checkAndMove(self._outfileName)
     self.outfile = os.open(self._outfileName,os.O_WRONLY | os.O_NONBLOCK | os.O_CREAT)
     if not self.outfile:
         raise("Could not open %s" % self._outfileName)
     else:
         log.msg("Opened %s" % self._outfileName)
     fdesc.setNonBlocking(self.outfile)
     
     self.running = 1
     def syncToDisc():
         """docstring for flushToDisk"""
         
         os.fsync(self.outfile)
         if self.running:
             reactor.callLater(5,syncToDisc)
     syncToDisc()
开发者ID:kyrios,项目名称:atemclient,代码行数:28,代码来源:files.py


示例10: __init__

 def __init__(self, factory, fd, reactor = None):
   # Read from standard input, make it Non Blocking
   self._fd = fd
   self.factory = factory
   fdesc.setNonBlocking(fd)
   # We open a file to read from 
   super(AdoptReadDescriptor, self).__init__(fd, reactor)
开发者ID:tuck182,项目名称:syslog-ng-mod-lumberjack-py,代码行数:7,代码来源:file_descriptor.py


示例11: __init__

    def __init__(self, reactor, proc, name, fileno, forceReadHack=False):
        """
        Initialize, specifying a Process instance to connect to.
        """
        abstract.FileDescriptor.__init__(self, reactor)
        fdesc.setNonBlocking(fileno)
        self.proc = proc
        self.name = name
        self.fd = fileno

        if not stat.S_ISFIFO(os.fstat(self.fileno()).st_mode):
            # If the fd is not a pipe, then the read hack is never
            # applicable.  This case arises when ProcessWriter is used by
            # StandardIO and stdout is redirected to a normal file.
            self.enableReadHack = False
        elif forceReadHack:
            self.enableReadHack = True
        else:
            # Detect if this fd is actually a write-only fd. If it's
            # valid to read, don't try to detect closing via read.
            # This really only means that we cannot detect a TTY's write
            # pipe being closed.
            try:
                os.read(self.fileno(), 0)
            except OSError:
                # It's a write-only pipe end, enable hack
                self.enableReadHack = True

        if self.enableReadHack:
            self.startReading()
开发者ID:antong,项目名称:twisted,代码行数:30,代码来源:process.py


示例12: receiveUpload

    def receiveUpload(self, upload):
        
        previous = getattr(self, 'beginning', 2)
        type, self.beginning, self.sequence  = unpack('<BBL', upload)
        self.remaining -= DATA_UPLOAD_LEN
        log.msg('Upload control %s prev: %s' % (self.beginning, previous))

        if self.beginning == 1:
            log.msg('A middle part of a file received')
            return self.receiveContent, self.remaining
            
        elif self.beginning == 2 and previous != 2 :
            log.msg('Last chunk of file received')
            return self.receiveContent, self.remaining
        
        elif self.beginning == 0 or (self.beginning == 2 and previous == 2):
            log.msg('First chunk of new file received')
            self.stamp = str(time.time())
            self.path = os.path.join(self.factory.storage, self.certificate, self.identity, self.stamp)
            self.generateUpdate(self.stamp)
            self.file = os.open(self.path, os.O_RDWR | os.O_CREAT)
            fdesc.setNonBlocking(self.file)
            return self.receiveContent, self.remaining

            if self.confirm:
                self.confirmToggle()
                self.sendConfirmation()
        
        else:
            log.msg('Something strange happend invalid las_chunk field!')
            return self.uselessReceived, self.remaining
开发者ID:grodniewicz,项目名称:zeroD,代码行数:31,代码来源:itprotocol.py


示例13: __init__

 def __init__(self, reactor):
     """Initialize.
     """
     self.reactor = reactor
     self.i, self.o = os.pipe()
     fdesc.setNonBlocking(self.i)
     fdesc.setNonBlocking(self.o)
     self.fileno = lambda: self.i
开发者ID:BackupTheBerlios,项目名称:tf-b4rt-svn,代码行数:8,代码来源:posixbase.py


示例14: start

def start(level=None, name="twisted", to_stdout=None, to_file=None, log_file_name=None):
    """
    Starts the logging for a single module.

    Each module should import this logging module and decide its level.

    The first time this is called, don't give any argument. It will log everything with the name "twisted".

    The programmer can choose the level from which to log, discarding any message with a lower level.
    Example : If level is INFO, the DEBUG messages (lower level) will not be displayed but the CRITICAL ones will.

    @param level: debug, info, error, warning or critical
    @type level: str
    @param to_stdout: Whether it should be printed to stdout. (False to disable)
    @param to_file: Whether it should be printed to file. (True to enable)
    @param name: What string to prefix with.
    @rtype: L{twisted.python.logging.PythonLoggingObserver}
    """
    global SYSTEMWIDE_TO_STDOUT
    global SYSTEMWIDE_TO_FILE
    global SYSTEMWIDE_LOG_FILE_NAME
    global SYSTEMWIDE_LEVEL

    if log_file_name is not None:
        SYSTEMWIDE_LOG_FILE_NAME = log_file_name
    if to_file is True:
        SYSTEMWIDE_TO_FILE = True
    if level is not None:
        SYSTEMWIDE_LEVEL = level
    logger = logging.getLogger(name)
    formatter = logging.Formatter('%(asctime)s %(name)-13s %(levelname)-8s %(message)s')
    set_level(SYSTEMWIDE_LEVEL, name)
    if to_stdout is True or to_stdout is False:
        SYSTEMWIDE_TO_STDOUT = to_stdout
    if to_file is True or to_file is False:
        SYSTEMWIDE_TO_FILE = to_file

    if SYSTEMWIDE_TO_STDOUT:
        so_handler = logging.StreamHandler(sys.stdout)
        if ENABLE_NON_BLOCKING_OUTPUT:
            fdesc.setNonBlocking(so_handler.stream) # NON-BLOCKING OUTPUT
        so_handler.setFormatter(formatter)
        logger.addHandler(so_handler)
    if SYSTEMWIDE_TO_FILE:
        if SYSTEMWIDE_LOG_FILE_NAME is None:
            raise RuntimeError("The log file name has not been set.")
        # file_handler = logging.FileHandler(log_file_name, mode='a', encoding='utf-8')
        file_handler = logging.FileHandler(SYSTEMWIDE_LOG_FILE_NAME) # FIXME: not catching IOError that could occur.
        if ENABLE_NON_BLOCKING_OUTPUT:
            fdesc.setNonBlocking(file_handler.stream) # NON-BLOCKING OUTPUT
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
    if name == 'twisted':
        observer = twisted_log.PythonLoggingObserver(name)
        observer.start()
        return logging.getLogger(name)
    else:
        return logging.getLogger(name)
开发者ID:alg-a,项目名称:scenic,代码行数:58,代码来源:logger.py


示例15: process_image

    def process_image(self, payload, **kwargs):
        """ Writes images to the cache """

        filecache_loc = settings.CACHE_LOCATION
        webcache_loc = settings.WEB_CACHE_LOCATION
        cache_filename_parts = payload['image_path'].split('.')
        filefront = cache_filename_parts[0]
        fileend = cache_filename_parts[1]
        cache_filename = ''

        original_filename = '%s.%s' % (
            filefront,
            fileend,
        )
        cache_filename = '%s_%sx%s_%s.%s' % (
            filefront,
            payload['width'],
            payload['height'],
            payload['mode'],
            fileend,
        )

        file_cache = os.path.join(filecache_loc, cache_filename)
        web_cache = os.path.join(webcache_loc, cache_filename)

        # Files are normally binned in subdir, create them in cache
        dirs = os.path.dirname(file_cache)
        try:
            os.makedirs(dirs)
        except os.error:
            pass

        if 'skip_resize' in payload.keys():
            # Just save/servwe original image as there is no resized image
            file_cache = os.path.join(filecache_loc, original_filename)
            web_cache = os.path.join(webcache_loc, original_filename)

        # Save image to be served
        fd = open(file_cache, 'w')
        fdesc.setNonBlocking(fd.fileno())
        yield fdesc.writeToFD(fd.fileno(), payload['image'])
        fd.close()

        if 'skip_resize' not in payload.keys():
            # If image to be served has beenr esized, also cache full size image
            file_cache = os.path.join(filecache_loc, original_filename)
            fd = open(file_cache, 'w')
            fdesc.setNonBlocking(fd.fileno())
            yield fdesc.writeToFD(fd.fileno(), payload['original_image'])
            fd.close()

        if settings.DEBUG:
            log.msg(
                "[%s] Cached image location: %s" % (datetime.now().isoformat(), file_cache),
                logLevel=logging.DEBUG
            )

        defer.returnValue(web_cache)
开发者ID:Frowse,项目名称:openross,代码行数:58,代码来源:cacher.py


示例16: __init__

 def __init__(self, fid, offset, length, bufLen = 8):
     self._fd = fid
     os.lseek(self._fd, offset, os.SEEK_SET)
     setNonBlocking(self._fd)
     self._readBufLen = bufLen
     self._readMaxLen = length
     self._readLen = 0
     self._allData = ''
     self.dataRecieved = AsyncFileReader.read_finish
开发者ID:xiaotianwu,项目名称:py_search,代码行数:9,代码来源:AsyncIO.py


示例17: getConf

 def getConf(self):
   try:
     logger.debug("Getting config file")
     with open(self.configPath) as f:
       fd = f.fileno()
       setNonBlocking(fd)
       readFromFD(fd, self.runConf)
   except IOError, e:
     self.d.errback(e)
开发者ID:tsturzl,项目名称:hookd-old,代码行数:9,代码来源:hook.py


示例18: openOutputFile

 def openOutputFile(self, path):
     if path is not None:
         try:
             # Open the file descriptor
             self.outputFile = open(path + '.h264')
             # Make it nonblocking
             fdesc.setNonBlocking(self.outputFile.fileno())
         except:
             print "Warning! Incoming video stream will not save to local file!"
             self.outputFile = None
开发者ID:sdrendall,项目名称:conditioningCage,代码行数:10,代码来源:mplayerStreamingInterface.py


示例19: test_setBlocking

 def test_setBlocking(self):
     """
     L{fdesc.setBlocking} sets a file description to blocking.
     """
     r, w = os.pipe()
     self.addCleanup(os.close, r)
     self.addCleanup(os.close, w)
     fdesc.setNonBlocking(r)
     fdesc.setBlocking(r)
     self.assertFalse(fcntl.fcntl(r, fcntl.F_GETFL) & os.O_NONBLOCK)
开发者ID:AmirKhooj,项目名称:VTK,代码行数:10,代码来源:test_fdesc.py


示例20: pipe

 def pipe(self):
     """
     Create a non-blocking pipe which will be closed after the currently
     running test.
     """
     read, write = os.pipe()
     self.addCleanup(os.close, read)
     self.addCleanup(os.close, write)
     setNonBlocking(read)
     setNonBlocking(write)
     return read, write
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:11,代码来源:test_sigchld.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python fdesc.writeToFD函数代码示例发布时间:2022-05-27
下一篇:
Python fdesc.readFromFD函数代码示例发布时间: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