Ejemplo n.º 1
0
 def worker_post_message(cls, key, payload):
     """
     Send a message to the workpool on stdout.
     Called by a worker.
     """
     msg = cls.build_message(key, payload)
     ns = netstring.encode(msg)
     sys.stdout.write(ns)
     sys.stdout.flush()
Ejemplo n.º 2
0
 def worker_post_message( cls, key, payload ):
     """
     Send a message to the workpool on stdout.
     Called by a worker.
     """
     msg = cls.build_message( key, payload )
     ns = netstring.encode( msg )
     sys.stdout.write( ns )
     sys.stdout.flush()
Ejemplo n.º 3
0
 def read(self, size):
     size=640 * 1024
     tmp=[]
     totlen = 0
     if self._tmp:
         a, self._tmp = self._tmp, None
         return a
     for i in self.it:
         s = netstring.encode(pickle.dumps(i, pickle.HIGHEST_PROTOCOL))
         l = len(s)
         if totlen==0 and l>size:
             raise Exception()
         elif l+totlen>size:
             self.totalsize+=totlen #ASD
             self._tmp = s
             return ''.join(tmp)
         else:
             tmp.append(s)
             totlen+=l
     
     self.totalsize+=totlen #
     return ''.join(tmp)
Ejemplo n.º 4
0
    def writemsg(self, wfd, msg):
        """
        Write message to stdin.
        Return True if successfully flushed
        Return False if we had to carry some over.
        Return None if the process is dead.

        NOTE: call flush() first, and only call this
        method if flush() returns True.
        """

        nm = netstring.encode(msg)
        rc = self.write_or_carry(wfd, nm)
        if rc is None:
            # process died
            return None

        if not rc:
            # carried
            return False

        # success!
        return True
Ejemplo n.º 5
0
    def writemsg( self, wfd, msg ):
        """
        Write message to stdin.
        Return True if successfully flushed
        Return False if we had to carry some over.
        Return None if the process is dead.

        NOTE: call flush() first, and only call this
        method if flush() returns True.
        """

        nm = netstring.encode( msg )
        rc = self.write_or_carry( wfd, nm )
        if rc is None:
            # process died 
            return None 

        if not rc:
            # carried 
            return False 

        # success!
        return True