Esempio n. 1
0
    def record(self, current, elapse, label):
        self.stats.request(elapse, name=label, current=current)
        if coro.get_local(DB_USAGE_MARKER, False):
            self.dbuse.request(elapse, name=label, current=current)
        self.wqsize.request(sum(map(len, self.requests)))

        data = (label, current, elapse, coro.current_thread().total_time(),
                coro.current_thread().long_time(),
                coro.current_thread().resume_count())

        self.wlimit.save(data[2],
                         data)  # longest wall clock + queue wait times
        self.elimit.save(data[3], data)  # longest execution times
        self.tlimit.save(data[4], data)  # longest non-yield times
        self.rlimit.save(data[5], data)  # most request yields
Esempio n. 2
0
    def record(self, current, elapse, label):
        self.stats.request(elapse, name = label, current = current)
        if coro.get_local(DB_USAGE_MARKER, False):
            self.dbuse.request(elapse, name = label, current = current)
        self.wqsize.request(sum(map(len, self.requests)))

        data = (
            label, current, elapse,
            coro.current_thread().total_time(),
            coro.current_thread().long_time(),
            coro.current_thread().resume_count())

        self.wlimit.save(data[2], data) # longest wall clock + queue wait times
        self.elimit.save(data[3], data) # longest execution times
        self.tlimit.save(data[4], data) # longest non-yield times
        self.rlimit.save(data[5], data) # most request yields
Esempio n. 3
0
    def _save_info(self, o):
        '''_save_info

        When an item is fetched from the queue, save information about
        the item request and the requester.
        '''
        data    = {'caller': pyinfo.rawstack(depth = 2), 'time':   time.time()}
        current = coro.current_thread()

        if current is not None:
            data.update({'thread': current.thread_id()})
            current.trace(True)

        self._item_save[id(o)] = data
        return o
Esempio n. 4
0
    def _wait_for_event(self, eventmask):
        me = coro.current_thread()
        if me is None:
            raise coro.CoroutineThreadError, "coroutine sockets in 'main'"

        coro.the_event_poll.register(self, eventmask)
        result = me.Yield()
        coro.the_event_poll.unregister(self)

        if result is None:
            raise coro.CoroutineSocketWake, 'file descriptor has been awakened'

        if result & eventmask:
            return None

        if result & ERROR_MASK:
            raise IOError(errno.EPIPE, 'Broken pipe')
        #
        # all cases should have been handled by this point
        return None
Esempio n. 5
0
    def _perform(self):
        current = coro.current_thread()
        if current is None:
            raise CoroutineCurlError, "coroutine curl in 'main'"

        while 1:
            ret = pycurl.E_CALL_MULTI_PERFORM

            while ret == pycurl.E_CALL_MULTI_PERFORM:
                ret, num = self._mult.perform()

            if not num:
                break
            #
            # build fdset and eventmask
            #
            read_set, send_set, excp_set = self._mult.fdset()
            if not read_set and not send_set:
                raise CoroutineCurlError, 'coroutine curl empty fdset'

            if read_set and send_set and read_set != send_set:
                raise CoroutineCurlError, 'coroutine curl bad fdset'

            self._fdno = (read_set + send_set)[0]
            eventmask  = 0

            if read_set:
                eventmask |= select.POLLIN

            if send_set:
                eventmask |= select.POLLOUT
            #
            # get timeout
            #
            # starting with pycurl version 7.16.0 the multi object
            # supplies the max yield timeout, otherwise we just use
            # a reasonable floor value.
            #
            if hasattr(self._mult, 'timeout'):
                timeout = self._mult.timeout()
            else:
                timeout = DEFAULT_YIELD_TIMEOUT
            #
            # wait
            #
            coro.the_event_poll.register(self, eventmask)
            result = current.Yield(timeout, 0)
            coro.the_event_poll.unregister(self)
            #
            # process results (result of 0 is a timeout)
            #
            self._fdno = None

            if result is None:
                raise CoroutineSocketWake, 'socket has been awakened'

            if 0 < (result & coro.ERROR_MASK):
                raise pycurl.error, (socket.EBADF, 'Bad file descriptor')

        queued, success, failed = self._mult.info_read()
        if failed:
            raise pycurl.error, (failed[0][1], failed[0][2])
Esempio n. 6
0
 def _wait_del(self):
     del(self._waits[coro.current_thread()])
     return reduce(lambda x, y: x|y, self._waits.values())
Esempio n. 7
0
 def _wait_add(self, mask):
     self._waits[coro.current_thread()] = mask
     return reduce(lambda x, y: x|y, self._waits.values())
Esempio n. 8
0
def sleep(value):
    thrd = coro.current_thread()
    if thrd is None:
        original["sleep"](value)
    else:
        thrd.Yield(timeout=value)
Esempio n. 9
0
def sleep(value):
    thrd = coro.current_thread()
    if thrd is None:
        original['sleep'](value)
    else:
        thrd.Yield(timeout=value)
Esempio n. 10
0
  def wait(self, id):

    self.__wait_map[id] = coro.current_thread().thread_id()
    self.__map_cond.wait()

    return None
Esempio n. 11
0
	def _perform(self):
		current = coro.current_thread()
		if current is None:
			raise CoroutineCurlError, "coroutine curl in 'main'"

		while 1:
			ret = pycurl.E_CALL_MULTI_PERFORM

			while ret == pycurl.E_CALL_MULTI_PERFORM:
				ret, num = self._mult.perform()

			if not num:
				break
			#
			# build fdset and eventmask
			#
			read_set, send_set, excp_set = self._mult.fdset()
			if not read_set and not send_set:
				raise CoroutineCurlError, 'coroutine curl empty fdset'

			if read_set and send_set and read_set != send_set:
				raise CoroutineCurlError, 'coroutine curl bad fdset'

			self._fdno = (read_set + send_set)[0]
			eventmask  = 0

			if read_set:
				eventmask |= select.POLLIN

			if send_set:
				eventmask |= select.POLLOUT
			#
			# get timeout
			#
			# starting with pycurl version 7.16.0 the multi object
			# supplies the max yield timeout, otherwise we just use
			# a reasonable floor value.
			#
			if hasattr(self._mult, 'timeout'):
				timeout = self._mult.timeout()
			else:
				timeout = DEFAULT_YIELD_TIMEOUT
			#
			# wait
			#
			coro.the_event_poll.register(self, eventmask)
			result = current.Yield(timeout, 0)
			coro.the_event_poll.unregister(self)
			#
			# process results (result of 0 is a timeout)
			#
			self._fdno = None		

			if result is None:
				raise CoroutineSocketWake, 'socket has been awakened'

			if 0 < (result & coro.ERROR_MASK):
				raise pycurl.error, (socket.EBADF, 'Bad file descriptor')

		queued, success, failed = self._mult.info_read()
		if failed:
			raise pycurl.error, (failed[0][1], failed[0][2])
Esempio n. 12
0
	def _wait_del(self):
		del(self._waits[coro.current_thread()])
		return reduce(lambda x, y: x|y, self._waits.values())
Esempio n. 13
0
	def _wait_add(self, mask):
		self._waits[coro.current_thread()] = mask
		return reduce(lambda x, y: x|y, self._waits.values())
Esempio n. 14
0
    def wait(self, id):

        self.__wait_map[id] = coro.current_thread().thread_id()
        self.__map_cond.wait()

        return None