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


Python fdesc.setNonBlocking函数代码示例

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


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


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