コード例 #1
0
ファイル: bookrun.py プロジェクト: Yhzhtk/bookcatch
def shot_one_book(book_id):
    '''抓一本书,返回是否成功'''
    try:
        print "=" * 50
        # 如果存在则跳过
        if bookorm.exist_book(book_id):
            print "%s has exist, continue" % book_id
            return True
        # 开始抓取
        print "begin crawl : %s" % book_id
        book = bookcrawl.crawl_book(book_id)
        if book != None:
            print book.bookName
            if bookcrawl.add_book_to_lebook(book_id):
                print "add book to lebook ok: " + book_id
                if bookorm.insert_book_chapter(book):
                    print "insert book ok: %s" % book_id
                    d_t = book.bookSize / 50 # 根据文件大小计算下载时间,每秒50k
                    if d_t < 15:
                        d_t = 15
                    if not bookshot.shot_first_book(book, down_time=d_t):
                        return False
                else:
                    print "insert book fail: %s" % book_id
            else:
                print "add book to lebook fail: " + book_id
        else:
            print "crawl book fail: " + book_id
    except:
        traceback.print_stack()
        return False
    return True
コード例 #2
0
ファイル: utilities.py プロジェクト: RedSkotina/SublimeLLDB
    def get_default(self, name, default, force=False):
        # Temporary name fix for when we're given a setting name with the prefix
        # In the future, this test will be gone and no setting will have
        # the 'lldb.' prefix
        if not name.startswith(self.__prefix):
            # Final code should be:
            name = self.__prefix + name
        else:
            debug(debugAny, 'Setting name has lldb prefix: %s' % name)
            import traceback
            traceback.print_stack()

        if not force and name in self.__values:
            return self.__values[name]

        setting = default

        if sublime.active_window() and sublime.active_window().active_view():
            setting = sublime.active_window().active_view().settings().get(name, default)

        if setting is default:
            setting = self.__settings.get(name, default)

        # Cache the setting value and setup a listener
        self.__values[name] = setting
        if name not in self.__settings_keys:
            self.__settings_keys.append(name)
            listener = self.create_listener(name)
            self.__settings.add_on_change(name, listener.on_change)

        debug(debugSettings, 'setting %s: %s' % (name, repr(setting)))
        return setting
コード例 #3
0
ファイル: util.py プロジェクト: OpenModelica/OMDev
def fatalError(explanation):
    if config.state['Debug']:
        print "omniidl: fatalError occurred, in debug mode."
        for line in explanation.split("\n"):
            print ">> " + line

        if have_traceback:
            print "Stack:"
            print "-------------------------"
            traceback.print_stack()
            print "Exception:"
            print "-------------------------"
            traceback.print_exc()
        sys.exit(1)
    
    lines = explanation.split("\n")
    lines = [ "Fatal error in C++ backend", "" ] + lines

    for line in lines:
        sys.stderr.write("omniidl: %s\n" % line)

    sys.stderr.write("""\

For more information (mailing list archives, bug reports etc.) please visit
the webpage:

  http://omniorb.sourceforge.net/

""")
    sys.exit(1)
コード例 #4
0
ファイル: __init__.py プロジェクト: 277800076/celery
def cry(out=None, sepchr='=', seplen=49):  # pragma: no cover
    """Return stack-trace of all active threads,
    taken from https://gist.github.com/737056."""
    import threading

    out = WhateverIO() if out is None else out
    P = partial(print, file=out)

    # get a map of threads by their ID so we can print their names
    # during the traceback dump
    tmap = {t.ident: t for t in threading.enumerate()}

    sep = sepchr * seplen
    for tid, frame in items(sys._current_frames()):
        thread = tmap.get(tid)
        if not thread:
            # skip old junk (left-overs from a fork)
            continue
        P('{0.name}'.format(thread))
        P(sep)
        traceback.print_stack(frame, file=out)
        P(sep)
        P('LOCAL VARIABLES')
        P(sep)
        pprint(frame.f_locals, stream=out)
        P('\n')
    return out.getvalue()
コード例 #5
0
ファイル: archiver.py プロジェクト: likan999/archiver
def log(level, *args):
  if level <= verbosity:
    prefix = str(level) + ": "
    print >> sys.stderr, prefix + "".join(map(str, args))
  if level == Level.Fatal:
    traceback.print_stack()
    sys.exit(1)
コード例 #6
0
ファイル: tdb_sql.py プロジェクト: Chris911/reddit
def add_request_info(select):
    from pylons import request
    from r2.lib import filters
    def sanitize(txt):
        return _spaces.sub(' ', txt).replace("/", "|").replace("-", "_").replace(';', "").replace("*", "").replace(r"/", "")
    s = StringIO.StringIO()
    traceback.print_stack( file = s)
    tb = s.getvalue()
    if tb:
        tb = tb.split('\n')[0::2]
        tb = [x.split('/')[-1] for x in tb if "/r2/" in x]
        tb = '\n'.join(tb[-15:-2])
    try:
        if (hasattr(request, 'path') and
            hasattr(request, 'ip') and
            hasattr(request, 'user_agent')):
            comment = '/*\n%s\n%s\n%s\n*/' % (
                tb or "", 
                filters._force_utf8(sanitize(request.fullpath)),
                sanitize(request.ip))
            return select.prefix_with(comment)
    except UnicodeDecodeError:
        pass

    return select
コード例 #7
0
ファイル: namespace.py プロジェクト: ianwj5int/pyslet
    def get_prefix(self, ns):
        """Returns the prefix assigned to a namespace

        ns
            The namespace URI as a character string.

        Returns None if no prefix is currently in force for this
        namespace."""
        if ns == XML_NAMESPACE:
            return "xml"
        elif ns is None:
            # Attributes with no namespace
            logging.error("Deprecation warning: None for ns")
            import traceback

            traceback.print_stack()
            return ""
        elif ns == NO_NAMESPACE:
            return ""
        prefix = None
        ei = self
        while prefix is None and ei is not None:
            prefix = ei._ns_to_prefix.get(ns, None)
            if prefix is not None:
                # this is the prefix to use, unless it has been reused...
                ej = self
                while ej is not ei:
                    if ej._prefix_to_ns.get(prefix, None) is not None:
                        # so prefix has been reused, keep searching
                        prefix = None
                        break
                    ej = ej.parent
            ei = ei.parent
        return prefix
コード例 #8
0
 def _dispatch_invoke(self, msg):
     log.debug("invoke has been received %s", msg)
     request = RequestStream()
     response = ResponseStream(msg.session, self, msg.event)
     try:
         event_closure = self._events.get(msg.event)
         if event_closure is not None:
             event_handler = event_closure()
             event_handler.invoke(request, response, self.loop)
             self.sessions[msg.session] = request
         else:
             self._logger.warn("there is no handler for event %s",
                               msg.event)
             response.error(CocaineErrno.ENOHANDLER,
                            "there is no handler for event %s" % msg.event)
     except (ImportError, SyntaxError) as err:
         response.error(CocaineErrno.EBADSOURCE,
                        "source is broken %s" % str(err))
         self.terminate(CocaineErrno.EBADSOURCE,
                        "source is broken")
     except Exception as err:
         log.error("invocation failed %s", err)
         traceback.print_stack()
         response.error(CocaineErrno.EINVFAILED,
                        "invocation failed %s" % err)
コード例 #9
0
ファイル: fonctions.py プロジェクト: Grahack/geophar
def full_trace(f, *args, **kw):
    if param.debug:
        print '** Debugging info **'
        traceback.print_stack()
        print "Calling %s with args %s, %s" % (f.func_name, args, kw)
        print '-------------------\n'
    return f(*args, **kw)
コード例 #10
0
 def playerTransfered(self,result,wip,wport,zport,zpassword):
     if not result[0] or not result[1]:
         traceback.print_stack()
         print "AssertionError: result has an empty value!"
         return
     wpassword = result[1]
     return (wip,wport,wpassword,zport,zpassword)
コード例 #11
0
ファイル: __init__.py プロジェクト: ackdesha/celery
def cry():  # pragma: no cover
    """Return stacktrace of all active threads.

    From https://gist.github.com/737056

    """
    tmap = {}
    main_thread = None
    # get a map of threads by their ID so we can print their names
    # during the traceback dump
    for t in threading.enumerate():
        if getattr(t, "ident", None):
            tmap[t.ident] = t
        else:
            main_thread = t

    out = StringIO()
    sep = "=" * 49 + "\n"
    for tid, frame in sys._current_frames().iteritems():
        thread = tmap.get(tid, main_thread)
        out.write("%s\n" % (thread.getName(),))
        out.write(sep)
        traceback.print_stack(frame, file=out)
        out.write(sep)
        out.write("LOCAL VARIABLES\n")
        out.write(sep)
        pprint(frame.f_locals, stream=out)
        out.write("\n\n")
    return out.getvalue()
コード例 #12
0
ファイル: js_cc.py プロジェクト: joeedh/webblender
def parse(data, file=None, create_logger=False, expand_loops=True, expand_generators=True):
    if file != None:
        glob.g_file = file

    if glob.g_add_newlines:
        data = add_newlines(data)
        # print(data[1017297])
        data = data.replace("\\n", "\n")
        for l in data.split("\n"):
            try:
                print(l)
            except UnicodeEncodeError:
                pass
        return data, StatementList()

    try:
        if glob.g_gen_es6:
            return parse_intern_es6(data)
        else:
            return parse_intern(
                data, create_logger=create_logger, expand_loops=expand_loops, expand_generators=expand_generators
            )
    except JSError:
        if glob.g_print_stack:
            traceback.print_stack()
            traceback.print_exc()

        glob.g_error = True
        return "", None
コード例 #13
0
ファイル: activity.py プロジェクト: parkr/Angels-vs-Demons
	def generate_page(self):
		try:
			f1 = open(self.template_page, "r")
			self.results = self.check_for_input()
			f2 = open(self.inventory_file, "r")
			self.stuff = f2.read().strip().split(", ")
			pickup_form_stuff = self.pickup_form()
			drop_form_stuff = self.drop_form()
			go_left_stuff = self.go_form('&larr;Go Left', 'left', 'http://cs.mcgill.ca/~pcrane/teamPage/cgi-bin/show.py')
			go_right_stuff = self.go_form('Go Right&rarr;', 'right', 'http://cs.mcgill.ca/~jmahen/cgi-bin/show.py')
			if self.loyalty == "none" or self.loyalty == "":
				self.loyalty = "none. <span class='error'>Move left to choose a side.</span>"
			print f1.read() % (pickup_form_stuff, drop_form_stuff, self.what_i_have, self.picked_up, self.dropped, self.loyalty, self.points, go_left_stuff['link'], go_right_stuff['link'], go_left_stuff['output'], go_right_stuff['output'])
		except Exception, e:
			import traceback, sys
			print
			print '<html><head><title>'
			print str(e)
			print '</title>'
			print '</head><body>'
			print '<h1>TRACEBACK</h1>'
			print '<pre>'
			print str(e)
			traceback.print_exc()
			traceback.print_stack()
			print "Unexpected error:", sys.exc_info()[0]
			print '</pre>'
			print '</body></html>'
コード例 #14
0
ファイル: locking.py プロジェクト: j-howell/calibre
 def release(self, *args):
     print('*' * 120, file=sys.stderr)
     print('release called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
     traceback.print_stack()
     RWLockWrapper.release(self)
     print('release done: thread id:', current_thread(), 'is_shared:', self._shlock.is_shared, 'is_exclusive:', self._shlock.is_exclusive, file=sys.stderr)
     print('_' * 120, file=sys.stderr)
コード例 #15
0
ファイル: prop.py プロジェクト: svn2github/Xpra
def prop_get(target, key, type, ignore_errors=False):
    if isinstance(type, list):
        scalar_type = type[0]
    else:
        scalar_type = type
    (pytype, atom, format, serialize, deserialize, terminator) = _prop_types[scalar_type]
    try:
        #print(atom)
        data = trap.call_synced(XGetWindowProperty, target, key, atom)
        #print(atom, repr(data[:100]))
    except NoSuchProperty:
        log.debug("Missing property %s (%s)", key, type)
        return None
    except (XError, PropertyError):
        if not ignore_errors:
            log.info("Missing window or missing property or wrong property type %s (%s)", key, type)
            import traceback
            traceback.print_stack()
        return None
    try:
        return _prop_decode(target, type, data)
    except:
        log.warn("Error parsing property %s (type %s); this may be a"
                 + " misbehaving application, or bug in Wimpiggy\n"
                 + "  Data: %r[...?]",
                 key, type, data[:160])
        raise
コード例 #16
0
ファイル: model.py プロジェクト: mmathioudakis/geotopics
    def predict_log_probs(self, test_data):
        num_points = test_data["coordinates"].shape[0]
        topic_log_prob_vector = np.zeros((self.num_topics, num_points))
        # topic_prob_vector = np.ones((self.num_topics, num_points))

        for z in range(self.num_topics):
            try:
                rv = stats.multivariate_normal(mean=self.topic_centers[z, :],
                                               cov=self.topic_covar[z, :, :], allow_singular=True)
                loc_log_prob = rv.logpdf(test_data["coordinates"]).reshape((num_points, 1))  # Nx1
                # loc_prob = rv.pdf(test_data["coordinates"]).reshape((num_points, 1))  # Nx1

            except:
                print("Error while computing geo log probabilities for test, dumping data.", "\n",
                      self.topic_centers[z, :], "\n", self.topic_covar[z, :, :], file=sys.stderr)
                traceback.print_stack(file=sys.stderr)
                sys.exit(1)

            feature_log_prob = np.zeros((num_points, 1))
            # feature_prob = np.ones((num_points, 1))
            for feature in self.beta_arrays.keys():
                beta = self.beta_arrays[feature][z]
                num_words = beta.shape[0]
                feature_log_prob += test_data[feature] * np.log(beta.reshape((num_words, 1)))  # (NxV * Vx1) = Nx1
                # feature_prob *= np.prod(np.power(beta.reshape((num_words, 1)).T, test_data[feature].todense()), axis=1)

            topic_log_prob_vector[z] = (loc_log_prob +
                                        feature_log_prob +
                                        np.tile(np.log(self.theta[0, z]), (num_points, 1))).flatten()
            # topic_prob_vector[z] = np.multiply(np.multiply(loc_prob, feature_prob),
            #                                    np.tile(self.theta[0, z], (num_points, 1))).flatten()

        # print("direct")
        # print(np.sum(np.log(np.sum(topic_prob_vector, axis=0))))
        return np.sum(utils.log_sum(topic_log_prob_vector, axis=0))
コード例 #17
0
ファイル: locking.py プロジェクト: j-howell/calibre
 def acquire(self):
     print('#' * 120, file=sys.stderr)
     print('acquire called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
     traceback.print_stack()
     RWLockWrapper.acquire(self)
     print('acquire done: thread id:', current_thread(), file=sys.stderr)
     print('_' * 120, file=sys.stderr)
コード例 #18
0
ファイル: test.py プロジェクト: scottfeldman/simp
def run(node, cmd):

    rsa = "/usr/share/simp/simp_rsa"
    port = sim.get_ssh_port(node)

    ssh_cmd = "ssh -q -o StrictHostKeyChecking=no " \
        "-o UserKnownHostsFile=/dev/null " \
        "-i %s -p %d simp@%s %s" % \
        (rsa, port, args.host, cmd)

    p = subprocess.Popen(ssh_cmd, shell=True,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    returncode = p.returncode

    if returncode != 0:
        print "******* FAILURE **********"
        print
        print "Output:"
        print out
        print
        print "Traceback:"
        print print_stack()
        print
        raise Exception(err)

    return out
コード例 #19
0
ファイル: functions.py プロジェクト: oflebbe/python-ldap
def _ldap_function_call(func, *args, **kwargs):
    """
    Wrapper function which locks calls to func with via
    module-wide ldap_lock
    """
    if __debug__:
        if _trace_level >= 1:
            _trace_file.write('*** %s.%s (%s,%s)\n' % (
                '_ldap', repr(func),
                repr(args), repr(kwargs)
            ))
            if _trace_level >= 3:
                traceback.print_stack(limit=_trace_stack_limit, file=_trace_file)
    _ldap_module_lock.acquire()
    try:
        try:
            result = func(*args, **kwargs)
        finally:
            _ldap_module_lock.release()
    except LDAPError as e:
        if __debug__ and _trace_level >= 2:
            _trace_file.write('=> LDAPError: %s\n' % (str(e)))
        raise
    if __debug__ and _trace_level >= 2:
        if result != None and result != (None, None):
            _trace_file.write('=> result: %s\n' % (repr(result)))
    return result
コード例 #20
0
ファイル: parse-usgs-json.py プロジェクト: carlgt1/qcn
def parseJSON(data, outFile, fileqcn, dbconn):                   # [1]
  ctr = 0
  try:
    json_data=open(FILE_USGS_JSON)
    data = simplejson.load(json_data)
    for item in data["features"]:
      ctr = ctr + 1 
      if ctr > 300:
         break
      sq.__init__()

      #print item['id'], item['properties']['time'],item['properties']['place'],item['properties']['mag'],item['properties']['url'],item['geometry']['coordinates'][0],item['geometry']['coordinates'][1],item['geometry']['coordinates'][2]

      sq.time = float(item['properties']['time'])/1000.0
      sq.strTime = datetime.fromtimestamp(int(sq.time)).strftime(TIME_PATTERN)
      sq.magnitude = float(item['properties']['mag'])
      sq.strDesc   = item['properties']['place']
      sq.strURL    = item['properties']['url']
      sq.latitude = float(item['geometry']['coordinates'][1])
      sq.longitude = float(item['geometry']['coordinates'][0])
      sq.strGUID = item['id']
      sq.depth_km = float(item['geometry']['coordinates'][2])
      sq.print_record(fileqcn, ctr, dbconn)
      sq.__init__()

    return ctr
  except:
    print "Error in parseJSON" + FILE_USGS_JSON
    traceback.print_stack()
    traceback.print_exc(file=sys.stdout)
    return -1
コード例 #21
0
ファイル: regression.py プロジェクト: USGS-Astrogeology/PySAT
    def fit(self, x, y, i=0):
        # if gaussian processes are being used, data dimensionality needs to be reduced before fitting
        if self.method[i] == 'GP':
            if self.reduce_dim == 'FastICA':
                print('Reducing dimensionality with ICA')
                do_ica = FastICA(n_components=self.n_components)
                self.do_reduce_dim = do_ica.fit(x)
            if self.reduce_dim == 'PCA':
                print('Reducing dimensionality with PCA')
                do_pca = PCA(n_components=self.n_components)
                self.do_reduce_dim = do_pca.fit(x)

            x = self.do_reduce_dim.transform(x)
        #try:
            print('Training model...')
        try:
            self.model.fit(x, y)
            self.goodfit = True
            print(self.model)
        except:
            self.goodfit = False
            if self.method[i] == 'GP':
                print('Model failed to train! (For GP this does not always indicate a problem, especially for low numbers of components.)')
                pass
            else:
                print('Model failed to train!')
                traceback.print_stack()

        if self.ransac:
            self.outliers = np.logical_not(self.model.inlier_mask_)
            print(str(np.sum(self.outliers)) + ' outliers removed with RANSAC')
コード例 #22
0
	def mousePressed(self, evt):
		if evt.isConsumedByWidgets():
			super(SelectionTool, self).mousePressed(evt)
			return
		elif evt.getButton() == fife.MouseEvent.LEFT:
			if self.session.selected_instances is None:
				# this is a very odd corner case, it should only happen after the session has been ended
				# we can't allow to just let it crash however
				self.log.error('Error: selected_instances is None. Please report this!')
				traceback.print_stack()
				self.log.error('Error: selected_instances is None. Please report this!')
				return
			instances = self.get_hover_instances(evt)
			self.select_old = frozenset(self.session.selected_instances) if evt.isControlPressed() else frozenset()

			instances = filter(self.is_selectable, instances)
			# On single click, only one building should be selected from the hover_instances.
			# The if is for [] and [single_item] cases (they crashed).
			# It acts as user would expect: instances[0] selects buildings in front first.
			instances = instances if len(instances) <= 1 else [instances[0]]

			self._update_selection(instances)

			self.select_begin = (evt.getX(), evt.getY())
			self.session.ingame_gui.hide_menu()
		elif evt.getButton() == fife.MouseEvent.RIGHT:
			target_mapcoord = self.get_exact_world_location(evt)
			for i in self.session.selected_instances:
				if i.movable:
					Act(i, target_mapcoord.x, target_mapcoord.y).execute(self.session)
		else:
			super(SelectionTool, self).mousePressed(evt)
			return
		evt.consume()
コード例 #23
0
ファイル: tpool.py プロジェクト: Aayush-Kasurde/eventlet
def execute(meth, *args, **kwargs):
    """
    Execute *meth* in a Python thread, blocking the current coroutine/
    greenthread until the method completes.

    The primary use case for this is to wrap an object or module that is not
    amenable to monkeypatching or any of the other tricks that Eventlet uses
    to achieve cooperative yielding.  With tpool, you can force such objects to
    cooperate with green threads by sticking them in native threads, at the cost
    of some overhead.
    """
    setup()
    # if already in tpool, don't recurse into the tpool
    # also, call functions directly if we're inside an import lock, because
    # if meth does any importing (sadly common), it will hang
    my_thread = threading.currentThread()
    if my_thread in _threads or imp.lock_held() or _nthreads == 0:
        return meth(*args, **kwargs)

    e = event.Event()
    _reqq.put((e, meth, args, kwargs))

    rv = e.wait()
    if isinstance(rv, tuple) \
            and len(rv) == 3 \
            and isinstance(rv[1], EXC_CLASSES):
        (c, e, tb) = rv
        if not QUIET:
            traceback.print_exception(c, e, tb)
            traceback.print_stack()
        six.reraise(c, e, tb)
    return rv
コード例 #24
0
ファイル: __init__.py プロジェクト: KWMalik/celery
def cry():  # pragma: no cover
    """Return stacktrace of all active threads.

    From https://gist.github.com/737056

    """
    tmap = {}
    main_thread = None
    # get a map of threads by their ID so we can print their names
    # during the traceback dump
    for t in threading.enumerate():
        if getattr(t, 'ident', None):
            tmap[t.ident] = t
        else:
            main_thread = t

    out = StringIO()
    P = partial(print, file=out)
    sep = '=' * 49
    for tid, frame in sys._current_frames().iteritems():
        thread = tmap.get(tid, main_thread)
        if not thread:
            # skip old junk (left-overs from a fork)
            continue
        P('{0.name}'.format(thread))
        P(sep)
        traceback.print_stack(frame, file=out)
        P(sep)
        P('LOCAL VARIABLES')
        P(sep)
        pprint(frame.f_locals, stream=out)
        P('\n')
    return out.getvalue()
コード例 #25
0
ファイル: LogInfo.py プロジェクト: geminiblue/oliyoapiserver
        def writeLog(logLevel,logMessage):
#                alogLevel = ["trace","warning","error"]
                sExceptMsg = ""
                if Config.B_SYS_DEBUG:
                    sExceptMsg += "\r\n**********************%s %s*********************************\r\n"%(logLevel.upper(),Func.fNow())
                    sExceptMsg += "\r\n%s Messages:%s"%(logLevel.upper(),str(logMessage))
                    sExceptMsg += "\r\n"
                if logLevel=="trace":
                        if Config.B_SYS_WRITE_LOG:
                                logger = LogInfo.initlog()
                                logger.info(logMessage)
                        if Config.B_SYS_TRACE:
                                print "\r\nTrace stack is flow:\r\n"
                                traceback.print_stack()
                                print "\r\n"                
                elif logLevel=="warning":
                        pass
                elif logLevel=="error":
                        exc_type, exc_value, exc_traceback = sys.exc_info()
                        if exc_type!=None:
                                sExceptMsg += "\r\n"
                                sExceptMsg += repr(traceback.format_tb(exc_traceback))
                                sExceptMsg += "\r\n"
                        else:
                                print "\r\nTrace stack is flow:\r\n"
                                traceback.print_stack()
                                sExceptMsg += "\r\n"
                         
                        if Config.B_SYS_WRITE_LOG and exc_type!=None:
                                logger = LogInfo.initlog()
                                logger.error(sExceptMsg)
                if Config.B_SYS_DEBUG:
                    sExceptMsg += "\r\n*********************%s END**********************************\r\n"%(logLevel.upper())
                    print   sExceptMsg      
コード例 #26
0
    def submit_job(self, job):
        id = uuid.uuid1()
        job['id'] = id
        print("Job %s created %s" % (job['id'], job['created'].strftime('%Y.%m.%d %H:%M:%S')))
        create_job_in_db(job)

        # put job in queue
        try:
            q.put(job, block=False)
        except Full as e:
            traceback.print_stack()
            traceback.print_exc()
            update_job_status(job['id'], "error")
            raise

        # update status to queued
        try:
            q_len = q.qsize()
            if (q_len >= QUEUE_WARN_SIZE):
                adminEmailer.warn("Queue is getting too long. There are currently %d items in the queue." % q_len)
            update_job_status(job['id'], "queued", "queue length %d" % q_len)
        except NotImplementedError:
            print("q.qsize not supported")
            update_job_status(job['id'], "queued")
        return id
コード例 #27
0
	def _show_tab(self, number):
		"""Used as callback function for the TabButtons.
		@param number: tab number that is to be shown.
		"""
		if not number in range(len(self._tabs)):
			# this usually indicates a non-critical error, therefore we can handle it without crashing
			traceback.print_stack()
			self.log.warning("Invalid tab number %s, available tabs: %s", number, self._tabs)
			return
		if self.current_tab.is_visible():
			self.current_tab.hide()
		new_tab = self._tabs[number]
		old_bg = self.content.findChild(name = "bg_%s" % self._tabs.index(self.current_tab))
		old_bg.image = self.current_tab.button_background_image
		name = str(self._tabs.index(self.current_tab))
		old_button = self.content.findChild(name=name)
		old_button.path = self.current_tab.path

		new_bg = self.content.findChild(name = "bg_%s" % number)
		new_bg.image = self.current_tab.button_background_image_active
		new_button = self.content.findChild(name=str(number))
		new_button.path = new_tab.path_active
		self.current_tab = new_tab
		# important to display the tabs correctly in front
		self.widget.hide()
		self.show()

		self._apply_layout_hack()
コード例 #28
0
ファイル: test_utils.py プロジェクト: BramDr/VIC
def process_error(error, vic_exe):
    '''Helper function to process possible error raised during testing'''
    tail = None
    if isinstance(error, VICRuntimeError):
        test_comment = 'Test failed during simulation'
        tail = vic_exe.stderr
    elif isinstance(error, VICTestError):
        test_comment = 'Test failed during testing of output files'
    elif isinstance(error, VICValgrindError):
        test_comment = 'Test failed due to memory error detected by valgrind'
        tail = vic_exe.stderr
    elif isinstance(error, VICReturnCodeError):
        test_comment = 'Test failed due to incorrect return code'
        tail = vic_exe.stderr
    elif isinstance(error, AssertionError):
        test_comment = 'AssertionError raised during testing'
    else:
        test_comment = 'Unknown test failure'
        traceback.print_stack()

    print('\t{0}'.format(test_comment))
    print('\t{0}'.format(error))
    if tail is not None:
        print('\tLast {0} lines of standard out:'.format(ERROR_TAIL))
        print_tail(tail, n=ERROR_TAIL)

    return test_comment, error
コード例 #29
0
ファイル: TaskGen.py プロジェクト: CodeMonk/fish
	def __setattr__(self, name, attr):
		real = typos.get(name, name)
		if real != name:
			warn('typo %s -> %s' % (name, real))
			if Logs.verbose > 0:
				traceback.print_stack()
		object.__setattr__(self, real, attr)
コード例 #30
0
ファイル: ldapobject.py プロジェクト: tiran/pyldap
 def _ldap_call(self,func,*args,**kwargs):
   """
   Wrapper method mainly for serializing calls into OpenLDAP libs
   and trace logs
   """
   self._ldap_object_lock.acquire()
   if __debug__:
     if self._trace_level>=1:
       self._trace_file.write('*** %s %s - %s\n%s\n' % (
         repr(self),
         self._uri,
         '.'.join((self.__class__.__name__,func.__name__)),
         pprint.pformat((args,kwargs))
       ))
       if self._trace_level>=9:
         traceback.print_stack(limit=self._trace_stack_limit,file=self._trace_file)
   diagnostic_message_success = None
   try:
     try:
       result = func(*args,**kwargs)
       if __debug__ and self._trace_level>=2:
         if func.__name__!="unbind_ext":
           diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
     finally:
       self._ldap_object_lock.release()
   except LDAPError as e:
     if __debug__ and self._trace_level>=2:
       self._trace_file.write('=> LDAPError - %s: %s\n' % (e.__class__.__name__,str(e)))
     raise
   else:
     if __debug__ and self._trace_level>=2:
       if not diagnostic_message_success is None:
         self._trace_file.write('=> diagnosticMessage: %s\n' % (repr(diagnostic_message_success)))
       self._trace_file.write('=> result:\n%s\n' % (pprint.pformat(result)))
   return result
コード例 #31
0
def abc():
    traceback.print_stack()
コード例 #32
0
ファイル: _k4abt.py プロジェクト: Ye-Hanyu/pyKinectAzure
def VERIFY(result, error):
    if result != K4ABT_RESULT_SUCCEEDED:
        print(error)
        traceback.print_stack()
        sys.exit(1)
コード例 #33
0
def interactive_debug_listen() -> None:
    signal.signal(signal.SIGUSR1,
                  lambda sig, stack: traceback.print_stack(stack))
    signal.signal(signal.SIGUSR2, interactive_debug)
コード例 #34
0
ファイル: test_nvenc_csc.py プロジェクト: TianyouLi/Xpra
    for i in range(h):
        p = i * w
        l = outputBuffer.data[p:p + w]
        log("%s: %s", hex(i).ljust(5), binascii.hexlify(str(l)))
        #debug("[%s] = %s / %s", i, ord(inputBuffer.data[i]), ord(outputBuffer.data[i]))

    #outputBuffer.data[1024] = numpy.byte(20)
    same = 0
    diff = 0
    zeroes = 0
    for i in range(w * h * 3 / 2):
        if ord(outputBuffer.data[i]) == 0:
            zeroes += 1
        if inputBuffer.data[i] != outputBuffer.data[i]:
            if diff < 10:
                log("buffer differs at %s: %s vs %s", i,
                    ord(inputBuffer.data[i]), ord(outputBuffer.data[i]))
            diff += 1
        else:
            same += 1

    log("end: same=%s, diff=%s, zeroes=%s", same, diff, zeroes)

except Exception as e:
    log("exception: %s" % e)
    import traceback
    traceback.print_stack()
finally:
    cuda_context.pop()
    cuda_context.detach()
コード例 #35
0
ファイル: storage.py プロジェクト: iminders/maddpg
 def fput_obj(self, local_path, minio_path):
     try:
         self.client.fput_object(self.bucket_name, minio_path, local_path)
     except Exception as err:
         logger.error(str(err))
         traceback.print_stack()
コード例 #36
0
ファイル: storage.py プロジェクト: iminders/maddpg
 def fget_object(self, bucket_name, obj_name, save_path):
     try:
         self.client.fget_object(bucket_name, obj_name, save_path)
     except ResponseError as err:
         logger.error(str(err))
         traceback.print_stack()
コード例 #37
0
ファイル: store.py プロジェクト: rasjani/codechecker
def main(args):
    """
    Store the defect results in the specified input list as bug reports in the
    database.
    """
    logger.setup_logger(args.verbose if 'verbose' in args else None)

    try:
        cmd_config.check_config_file(args)
    except FileNotFoundError as fnerr:
        LOG.error(fnerr)
        sys.exit(1)

    if not host_check.check_zlib():
        raise Exception("zlib is not available on the system!")

    # To ensure the help message prints the default folder properly,
    # the 'default' for 'args.input' is a string, not a list.
    # But we need lists for the foreach here to work.
    if isinstance(args.input, str):
        args.input = [args.input]

    if 'name' not in args:
        LOG.debug("Generating name for analysis...")
        generated = __get_run_name(args.input)
        if generated:
            setattr(args, 'name', generated)
        else:
            LOG.error("No suitable name was found in the inputs for the "
                      "analysis run. Please specify one by passing argument "
                      "--name run_name in the invocation.")
            sys.exit(2)  # argparse returns error code 2 for bad invocations.

    LOG.info("Storing analysis results for run '" + args.name + "'")

    if 'force' in args:
        LOG.info("argument --force was specified: the run with name '" +
                 args.name + "' will be deleted.")

    # Setup connection to the remote server.
    client = libclient.setup_client(args.product_url)

    _, zip_file = tempfile.mkstemp('.zip')
    LOG.debug("Will write mass store ZIP to '%s'...", zip_file)

    try:
        LOG.debug("Assembling zip file.")
        try:
            assemble_zip(args.input, zip_file, client)
        except Exception as ex:
            print(ex)
            import traceback
            traceback.print_stack()
            LOG.error("Failed to assemble zip file.")
            sys.exit(1)

        zip_size = os.stat(zip_file).st_size
        LOG.debug("Assembling zip done, size is %s", sizeof_fmt(zip_size))

        if zip_size > MAX_UPLOAD_SIZE:
            LOG.error("The result list to upload is too big (max: %s).",
                      sizeof_fmt(MAX_UPLOAD_SIZE))
            sys.exit(1)

        b64zip = ""
        with open(zip_file, 'rb') as zf:
            b64zip = base64.b64encode(zf.read()).decode("utf-8")
        if len(b64zip) == 0:
            LOG.info("Zip content is empty, nothing to store!")
            sys.exit(1)

        context = webserver_context.get_context()

        trim_path_prefixes = args.trim_path_prefix if \
            'trim_path_prefix' in args else None

        description = args.description if 'description' in args else None

        LOG.info("Storing results to the server...")
        client.massStoreRun(args.name, args.tag if 'tag' in args else None,
                            str(context.version), b64zip, 'force' in args,
                            trim_path_prefixes, description)

        # Storing analysis statistics if the server allows them.
        if client.allowsStoringAnalysisStatistics():
            storing_analysis_statistics(client, args.input, args.name)

        LOG.info("Storage finished successfully.")
    except RequestFailed as reqfail:
        if reqfail.errorCode == ErrorCode.SOURCE_FILE:
            header = ['File', 'Line', 'Checker name']
            table = twodim.to_str('table', header,
                                  [c.split('|') for c in reqfail.extraInfo])
            LOG.warning(
                "Setting the review statuses for some reports failed "
                "because of non valid source code comments: "
                "%s\n %s", reqfail.message, table)
        sys.exit(1)
    except Exception as ex:
        import traceback
        traceback.print_stack()
        LOG.info("Storage failed: %s", str(ex))
        sys.exit(1)
    finally:
        os.remove(zip_file)
コード例 #38
0
    def setup(self, session_expiration=30):
        # Patch the two-factor verification to avoid intermittent errors
        self.patcher = mock.patch('db.Journalist.verify_token')
        self.mock_journalist_verify_token = self.patcher.start()
        self.mock_journalist_verify_token.return_value = True

        self.patcher2 = mock.patch('source_app.main.get_entropy_estimate')
        self.mock_get_entropy_estimate = self.patcher2.start()
        self.mock_get_entropy_estimate.return_value = 8192

        signal.signal(signal.SIGUSR1, lambda _, s: traceback.print_stack(s))

        env.create_directories()
        self.gpg = env.init_gpg()
        db.init_db()

        source_port = self._unused_port()
        journalist_port = self._unused_port()

        self.source_location = "http://localhost:%d" % source_port
        self.journalist_location = "http://localhost:%d" % journalist_port

        # Allow custom session expiration lengths
        self.session_expiration = session_expiration

        def start_source_server():
            # We call Random.atfork() here because we fork the source and
            # journalist server from the main Python process we use to drive
            # our browser with multiprocessing.Process() below. These child
            # processes inherit the same RNG state as the parent process, which
            # is a problem because they would produce identical output if we
            # didn't re-seed them after forking.
            Random.atfork()

            config.SESSION_EXPIRATION_MINUTES = self.session_expiration

            source_app = create_app(config)

            source_app.run(
                port=source_port,
                debug=True,
                use_reloader=False,
                threaded=True)

        def start_journalist_server():
            Random.atfork()
            journalist.app.run(
                port=journalist_port,
                debug=True,
                use_reloader=False,
                threaded=True)

        self.source_process = Process(target=start_source_server)
        self.journalist_process = Process(target=start_journalist_server)

        self.source_process.start()
        self.journalist_process.start()

        for tick in range(30):
            try:
                requests.get(self.source_location)
                requests.get(self.journalist_location)
            except:
                time.sleep(1)
            else:
                break

        if not hasattr(self, 'override_driver'):
            self.driver = self._create_webdriver(self._prepare_webdriver())

        # Polls the DOM to wait for elements. To read more about why
        # this is necessary:
        #
        # http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html
        #
        # A value of 5 is known to not be enough in some cases, when
        # the machine hosting the tests is slow, reason why it was
        # raised to 10. Setting the value to 60 or more would surely
        # cover even the slowest of machine. However it also means
        # that a test failing to find the desired element in the DOM
        # will only report failure after 60 seconds which is painful
        # for quickly debuging.
        #
        self.driver.implicitly_wait(10)

        # Set window size and position explicitly to avoid potential bugs due
        # to discrepancies between environments.
        self.driver.set_window_position(0, 0)
        self.driver.set_window_size(1024, 768)

        self.secret_message = ('These documents outline a major government '
                               'invasion of privacy.')
コード例 #39
0
ファイル: debug.py プロジェクト: scottwedge/EXtra-foam
 def write(self, x):
     self.stdout.write(x)
     traceback.print_stack()
コード例 #40
0
def _print_nativethreads():
    for threadId, stack in sys._current_frames().items():
        print(threadId)
        traceback.print_stack(stack)
        print()
コード例 #41
0
ファイル: observer.py プロジェクト: jobfeikens/grid-monitor
 def throw(self, error: Exception) -> None:
     import traceback
     traceback.print_stack()
     if error:
         raise error
     1 / 0  # Raise division by zero
コード例 #42
0
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
    traceback.print_stack()
    log = file if hasattr(file, 'write') else sys.stderr
    log.write(warnings.formatwarning(message, category, filename, lineno, line))
コード例 #43
0
 def handel_error(self, error, response, request_args, request_kwargs):
     kodi.log(error)
     if response is not None:
         kodi.log(response.url)
     traceback.print_stack()
     raise error
コード例 #44
0
    def toString(self, default_suffix='', format='hh:mm', rounding=False):
        if self.hour < 0:
            logging.error('t<0! %s ' % self.hour)
            logging.error(traceback.print_stack())

        msec, secs = modf(self.hour * 3600)
        msec = round(msec * 1000)
        if msec == 1000:
            msec = 0
            secs += 1

        hour = secs // 3600
        secs = secs % 3600

        suffix = default_suffix
        if format[-1] == '*':
            if hour >= 24:
                suffix = '*'
        else:
            if hour >= 24:
                hour -= 24
                suffix = '(+1)'  # Default notation for times > 23:59

        minute = secs // 60
        secs = secs % 60
        second = secs

        if format in ('hh:mm', 'hh:mm*'):
            # Rounding done if 30 seconds have elapsed
            return '%02d:%02d%s' % (hour, minute +
                                    ((secs +
                                      (msec >= 500)) >= 30) * rounding, suffix)
        elif format in ('hh:mm:ss', 'hh:mm:ss*'):
            # Rounding done if 500 milliseconds have elapsed
            return '%02d:%02d:%02d%s' % (hour, minute, second +
                                         (msec >= 500) * rounding, suffix)
        elif format in ('hh:mm:ss.sss', 'hh:mm:ss.sss*'):
            return '%02d:%02d:%02d.%03d%s' % (hour, minute, second, msec,
                                              suffix)
        elif format == 'gg-pp':  # ghatika-pal
            secs = round(self.hour * 3600)
            gg = secs // 1440
            secs = secs % 1440
            pp = secs // 24
            return ('%d-%d' % (gg, pp))
        elif format == 'gg-pp-vv':  # ghatika-pal-vipal
            vv_tot = round(self.hour * 3600 / 0.4)
            logging.debug(vv_tot)
            vv = vv_tot % 60
            logging.debug(vv)
            vv_tot = (vv_tot - vv) // 60
            logging.debug(vv_tot)
            pp = vv_tot % 60
            logging.debug(pp)
            vv_tot = (vv_tot - pp) // 60
            logging.debug(vv_tot)
            gg = vv_tot
            logging.debug(gg)
            return ('%d-%d-%d' % (gg, pp, vv))
        else:
            raise Exception("""Unknown format""")
コード例 #45
0
 def run_func(*args, **kwargs):
     traceback.print_stack()
     return func(*args, **kwargs)
コード例 #46
0
ファイル: usufy.py プロジェクト: vicsanjinez/osrframework
def main(args):
    """
    Main function to launch usufy.

    The function is created in this way so as to let other applications make
    use of the full configuration capabilities of the application. The
    parameters received are used as parsed by this modules `getParser()`.

    Args:
    -----
        args: The parameters as processed by this modules `getParser()`.

    Returns:
    --------
        dict: A Json representing the matching results.
    """
    # Recovering the logger
    # Calling the logger when being imported
    osrframework.utils.logger.setupLogger(loggerName="osrframework.usufy",
                                          verbosity=args.verbose,
                                          logFolder=args.logfolder)
    # From now on, the logger can be recovered like this:
    logger = logging.getLogger("osrframework.usufy")

    if not args.maltego:
        print(general.title(banner.text))

        sayingHello = """
usufy.py Copyright (C) F. Brezo and Y. Rubio (i3visio) 2014-2017

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. For additional info,
visit """ + general.LICENSE_URL + "\n"
        logger.info(sayingHello)
        print(general.title(sayingHello))
        logger.info("Starting usufy.py...")

    if args.license:
        general.showLicense()
    elif args.fuzz:
        logger.info("Performing the fuzzing tasks...")
        res = fuzzUsufy(args.fuzz, args.fuzz_config)
        logger.info("Recovered platforms:\n" + str(res))
    else:
        logger.debug("Recovering the list of platforms to be processed...")
        # Recovering the list of platforms to be launched
        listPlatforms = platform_selection.getPlatformsByName(
            platformNames=args.platforms,
            tags=args.tags,
            mode="usufy",
            excludePlatformNames=args.exclude)
        logger.debug("Platforms recovered.")

        if args.info:
            # Information actions...
            if args.info == 'list_platforms':
                infoPlatforms = "Listing the platforms:\n"
                for p in listPlatforms:
                    infoPlatforms += "\t\t" + (str(p) + ": ").ljust(
                        16, ' ') + str(p.tags) + "\n"
                logger.info(infoPlatforms)
                return infoPlatforms
            elif args.info == 'list_tags':
                logger.info("Listing the tags:")
                tags = {}
                # Going through all the selected platforms to get their tags
                for p in listPlatforms:
                    for t in p.tags:
                        if t not in tags.keys():
                            tags[t] = 1
                        else:
                            tags[t] += 1
                infoTags = "List of tags:\n"
                # Displaying the results in a sorted list
                for t in tags.keys():
                    infoTags += "\t\t" + (t + ": ").ljust(16, ' ') + str(
                        tags[t]) + "  time(s)\n"
                logger.info(infoTags)
                return infoTags
            else:
                pass

        # performing the test
        elif args.benchmark:
            logger.warning(
                "The benchmark mode may last some minutes as it will be performing similar queries to the ones performed by the program in production. "
            )
            logger.info("Launching the benchmarking tests...")
            platforms = platform_selection.getAllPlatformNames("usufy")
            res = benchmark.doBenchmark(platforms)
            strTimes = ""
            for e in sorted(res.keys()):
                strTimes += str(e) + "\t" + str(res[e]) + "\n"
            logger.info(strTimes)
            return strTimes

        # showing the tags of the usufy platforms
        elif args.show_tags:
            logger.info("Collecting the list of tags...")
            tags = platform_selection.getAllPlatformNamesByTag("usufy")
            logger.info(json.dumps(tags, indent=2))
            print(
                general.info(
                    "This is the list of platforms grouped by tag.\n"))
            print(json.dumps(tags, indent=2, sort_keys=True))
            print(
                general.info(
                    "[Tip] Remember that you can always launch the platform using the -t option followed by any of the aforementioned.\n"
                ))
            return tags

        # Executing the corresponding process...
        else:
            # Showing the execution time...
            if not args.maltego:
                startTime = dt.datetime.now()
                print(
                    str(startTime) + "\tStarting search in " +
                    general.emphasis(str(len(listPlatforms))) +
                    " platform(s)... Relax!\n")
                print(general.emphasis("\tPress <Ctrl + C> to stop...\n"))

            # Defining the list of users to monitor
            nicks = []
            logger.debug("Recovering nicknames to be processed...")
            if args.nicks:
                for n in args.nicks:
                    # TO-DO
                    #     A trick to avoid having the processing of the properties when being queried by Maltego
                    if "properties.i3visio" not in n:
                        nicks.append(n)
            else:
                # Reading the nick files
                try:
                    nicks = args.list.read().splitlines()
                except:
                    logger.error(
                        "ERROR: there has been an error when opening the file that stores the nicks.\tPlease, check the existence of this file."
                    )

            # Definning the results
            res = []

            if args.output_folder != None:
                # if Verifying an output folder was selected
                logger.debug("Preparing the output folder...")
                if not args.maltego:
                    if not os.path.exists(args.output_folder):
                        logger.warning(
                            "The output folder \'" + args.output_folder +
                            "\' does not exist. The system will try to create it."
                        )
                        os.makedirs(args.output_folder)
                # Launching the process...
                res = processNickList(nicks,
                                      listPlatforms,
                                      args.output_folder,
                                      avoidProcessing=args.avoid_processing,
                                      avoidDownload=args.avoid_download,
                                      nThreads=args.threads,
                                      verbosity=args.verbose,
                                      logFolder=args.logfolder)

            else:
                try:
                    res = processNickList(nicks,
                                          listPlatforms,
                                          nThreads=args.threads,
                                          verbosity=args.verbose,
                                          logFolder=args.logfolder)
                except Exception as e:
                    print(
                        general.error(
                            "Exception grabbed when processing the nicks: " +
                            str(e)))
                    print(general.error(traceback.print_stack()))

            logger.info("Listing the results obtained...")
            # We are going to iterate over the results...
            strResults = "\t"

            # Structure returned
            """
            [
                {        print

                  "attributes": [
                    {
                      "attributes": [],
                      "type": "i3visio.uri",
                      "value": "http://twitter.com/i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.alias",
                      "value": "i3visio"
                    },
                    {
                      "attributes": [],
                      "type": "i3visio.platform",
                      "value": "Twitter"
                    }
                  ],
                  "type": "i3visio.profile",
                  "value": "Twitter - i3visio"
                }
                ,
                ...
            ]
            """
            for r in res:
                # The format of the results (attributes) for a given nick is a list as follows:

                for att in r["attributes"]:
                    # iterating through the attributes
                    platform = ""
                    uri = ""
                    for details in att["attributes"]:
                        if details["type"] == "i3visio.platform":
                            platform = details["value"]
                        if details["type"] == "i3visio.uri":
                            uri = details["value"]
                    try:
                        strResults += (str(platform) + ":").ljust(
                            16, ' ') + " " + str(uri) + "\n\t\t"
                    except:
                        pass

                logger.info(strResults)

            # Generating summary files for each ...
            if args.extension:
                # Storing the file...
                logger.info("Creating output files as requested.")
                if not args.maltego:
                    # Verifying if the outputPath exists
                    if not os.path.exists(args.output_folder):
                        logger.warning(
                            "The output folder \'" + args.output_folder +
                            "\' does not exist. The system will try to create it."
                        )
                        os.makedirs(args.output_folder)

                    # Grabbing the results
                    fileHeader = os.path.join(args.output_folder,
                                              args.file_header)

                    # Iterating through the given extensions to print its values
                    for ext in args.extension:
                        # Generating output files
                        general.exportUsufy(res, ext, fileHeader)

            # Generating the Maltego output
            if args.maltego:
                general.listToMaltego(res)
            # Printing the results if requested
            else:
                now = dt.datetime.now()
                print(
                    str(now) +
                    "\tA summary of the results obtained are shown in the following table:\n"
                )
                print(general.success(general.usufyToTextExport(res)))

                if args.web_browser:
                    general.openResultsInBrowser(res)

                now = dt.datetime.now()
                print(
                    "\n" + str(now) +
                    "\tYou can find all the information collected in the following files:"
                )
                for ext in args.extension:
                    # Showing the output files
                    print("\t" + general.emphasis(fileHeader + "." + ext))

                # Showing the execution time...
                endTime = dt.datetime.now()
                print("\n" + str(endTime) + "\tFinishing execution...\n")
                print("Total time consumed:\t" +
                      general.emphasis(str(endTime - startTime)))
                print("Average seconds/query:\t" + general.emphasis(
                    str((endTime - startTime).total_seconds() /
                        len(listPlatforms))) + " seconds\n")

                # Urging users to place an issue on Github...
                print(banner.footer)

            return res
コード例 #47
0
def _print_greenthreads():
    for i, gt in enumerate(_find_objects(greenlet.greenlet)):
        print(i, gt)
        traceback.print_stack(gt.gr_frame)
        print()
コード例 #48
0
def signal_print_traceback(signo, frame):
    print(traceback.print_stack(frame))
コード例 #49
0
    def run(self):

        dbloop = task.LoopingCall(Blockchain.Default().PersistBlocks)
        dbloop.start(.1)

        Blockchain.Default().PersistBlocks()

        tokens = [(Token.Neo, 'NEO'), (Token.Default, ' cli. Type '),
                  (Token.Command, "'help' "), (Token.Default, 'to get started')]

        print_tokens(tokens, self.token_style)
        print("\n")

        timebase = time.time()

        while self.go_on:

            try:
                if len(self.mycommands) > 0:
                    timenow = time.time()
                    if timenow - timebase > 3: #wait 3 seconds
                        timebase = timenow
                        result = self.mycommands.pop()
                    else:
                        time.sleep(0.5) # slow refresh
                        continue
                    #time.sleep(3)
                else:
                    result = prompt("neo> ",
                                completer=self.get_completer(),
                                history=self.history,
                                get_bottom_toolbar_tokens=self.get_bottom_toolbar,
                                style=self.token_style,
                                refresh_interval=3
                                )
                                # Control-D pressed: quit

                #print("result=",result)
                #print("mycommands ->", self.mycommands)
            except EOFError:
                return self.quit()
            except KeyboardInterrupt:
                # Control-C pressed: do nothing
                continue

            try:
                command, arguments = self.parse_result(result)

                if command is not None and len(command) > 0:
                    command = command.lower()

                    if command == 'quit' or command == 'exit':
                        time.sleep(2) # consolidate chain
                        self.quit()
                    elif command == 'help':
                        self.help()
                    elif command == 'create':
                        self.do_create(arguments)
                    elif command == 'open':
                        self.do_open(arguments)
                    elif command == 'build':
                        self.do_build(arguments)
                    elif command == 'load_run':
                        self.do_load_n_run(arguments)
                    elif command == 'import':
                        self.do_import(arguments)
                    elif command == 'export':
                        self.do_export(arguments)
                    elif command == 'wallet':
                        self.show_wallet(arguments)
                    elif command == 'send':
                        self.do_send(arguments)
                    elif command == 'sign':
                        self.do_sign(arguments)
                    elif command == 'block':
                        self.show_block(arguments)
                    elif command == 'tx':
                        self.show_tx(arguments)
                    elif command == 'header':
                        self.show_header(arguments)
                    elif command == 'account':
                        self.show_account_state(arguments)
                    elif command == 'asset':
                        self.show_asset_state(arguments)
                    elif command == 'contract':
                        self.show_contract_state(arguments)
                    elif command == 'testinvoke':
                        self.test_invoke_contract(arguments)
                    elif command == 'mem':
                        self.show_mem()
                    elif command == 'nodes' or command == 'node':
                        self.show_nodes()
                    elif command == 'state':
                        self.show_state()
                    elif command == 'debugstorage':
                        self.handle_debug_storage(arguments)
                    elif command == 'config':
                        self.configure(arguments)
                    elif command is None:
                        print('please specify a command')
                    else:
                        print("command %s not found" % command)

            except Exception as e:

                print("could not execute command: %s " % e)
                traceback.print_stack()
                traceback.print_exc()
コード例 #50
0
ファイル: utils.py プロジェクト: songroom2016/vaex
def print_stack_trace(*args, **kwargs):
    import traceback
    print("args: ", args, kwargs)
    traceback.print_stack()
コード例 #51
0
 def prn():
     traceback.print_stack()
コード例 #52
0
def gPixmapPtr_deref(self):
    print "gPixmapPtr.__deref__() is deprecated please completely remove the \".__deref__()\" call!"
    import traceback
    traceback.print_stack(limit=2)
    return self
コード例 #53
0
ファイル: parallel.py プロジェクト: supertanglang/chromium.bb
  def Wait(self):
    """Wait for the task to complete.

    Output from the task is printed as it runs.

    If an exception occurs, return a string containing the traceback.
    """
    try:
      # Flush stdout and stderr to be sure no output is interleaved.
      sys.stdout.flush()
      sys.stderr.flush()

      # File position pointers are shared across processes, so we must open
      # our own file descriptor to ensure output is not lost.
      self._WaitForStartup()
      silent_death_time = time.time() + self.SILENT_TIMEOUT
      results = []
      with open(self._output.name, 'r') as output:
        pos = 0
        running, exited_cleanly, task_errors, all_errors = (True, False, [], [])
        while running:
          # Check whether the process is still alive.
          running = self.is_alive()

          try:
            errors, results = \
                self._queue.get(True, self.PRINT_INTERVAL)
            if errors:
              task_errors.extend(errors)
              all_errors.extend(errors)

            running = False
            exited_cleanly = True
          except Queue.Empty:
            pass

          if not running:
            # Wait for the process to actually exit. If the child doesn't exit
            # in a timely fashion, kill it.
            self.join(self.EXIT_TIMEOUT)
            if self.exitcode is None:
              msg = '%r hung for %r seconds' % (self, self.EXIT_TIMEOUT)
              all_errors.extend(
                  failures_lib.CreateExceptInfo(ProcessExitTimeout(msg), ''))
              self._KillChildren([self])
            elif not exited_cleanly:
              msg = ('%r exited unexpectedly with code %s'
                     % (self, self.exitcode))
              all_errors.extend(
                  failures_lib.CreateExceptInfo(ProcessUnexpectedExit(msg), ''))

          # Read output from process.
          output.seek(pos)
          buf = output.read(_BUFSIZE)

          if len(buf) > 0:
            silent_death_time = time.time() + self.SILENT_TIMEOUT
          elif running and time.time() > silent_death_time:
            msg = ('No output from %r for %r seconds' %
                   (self, self.SILENT_TIMEOUT))
            all_errors.extend(
                failures_lib.CreateExceptInfo(ProcessSilentTimeout(msg), ''))
            self._KillChildren([self])

            # Read remaining output from the process.
            output.seek(pos)
            buf = output.read(_BUFSIZE)
            running = False

          # Print output so far.
          while len(buf) > 0:
            sys.stdout.write(buf)
            pos += len(buf)
            if len(buf) < _BUFSIZE:
              break
            buf = output.read(_BUFSIZE)

          # Print error messages if anything exceptional occurred.
          if len(all_errors) > len(task_errors):
            logging.PrintBuildbotStepFailure()
            msg = '\n'.join(x.str for x in all_errors if x)
            logging.warning(msg)
            traceback.print_stack()

          sys.stdout.flush()
          sys.stderr.flush()

      # Propagate any results.
      for result in results:
        results_lib.Results.Record(*result)

    finally:
      self.Cleanup(silent=True)

    # If an error occurred, return it.
    return all_errors
コード例 #54
0
ファイル: _context.py プロジェクト: determined-ai/determined
 def stacktrace_on_sigusr1(signum: Any, frame: Any) -> None:
     traceback.print_stack(frame, file=sys.stderr)
     # old_handler may be None, SIG_IGN, or SIG_DFL.  It happens that SIG_DFL would be a noop for
     # SIGUSR1 so we don't have to worry about that case.
     if callable(old_handler):
         old_handler(signum, frame)
コード例 #55
0
 def _sleep(n):
     print('WARNING: Time sleep for {0}s'.format(n))
     import traceback
     traceback.print_stack()
     _orig_sleep(n)
コード例 #56
0
def test(x):
    if not x:
        print("Error")
        traceback.print_stack()
        sys.exit(1)
コード例 #57
0
def log_trace():
    print 'start traceback:'
    traceback.print_stack(limit=None)
    print 'end traceback:'
コード例 #58
0
 def get_num_matrix(self, get_matrix_weight, phys_target=None):
     import traceback
     traceback.print_stack()
     assert False, "this should not be called"
コード例 #59
0
 def dec_stack_trace(*args):
     print_stack()
     return function(*args)
コード例 #60
0
def trace():
    traceback.print_stack()