Python logging.warning() Examples
The following are 30
code examples of logging.warning().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logging
, or try the search function
.
Example #1
Source File: test_docstring.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
def import_into(globs, module, names=None, error_on_overwrite=True): """Import names from module into the globs dict. Parameters ---------- """ mod_names = dir(module) if names is not None: for name in names: assert name in mod_names, '%s not found in %s' % ( name, module) mod_names = names for name in mod_names: if name in globs and globs[name] is not getattr(module, name): error_msg = 'Attempting to overwrite definition of %s' % name if error_on_overwrite: raise RuntimeError(error_msg) logging.warning('%s', error_msg) globs[name] = getattr(module, name) return globs
Example #2
Source File: splitunderscoretokens.py From udapi-python with GNU General Public License v3.0 | 6 votes |
def process_node(self, node): if node.form != '_' and '_' in node.form: forms = node.form.split('_') lemmas = node.lemma.split('_') if len(forms) != len(lemmas): logging.warning("Different number of underscores in %s and %s, skipping.", node.form, node.lemma) return last_node = node deprel = self.deprel_for(node) for form, lemma in zip(forms[1:], lemmas[1:]): new_node = node.create_child(form=form, lemma=lemma, upos=node.upos, xpos=node.xpos, deprel=deprel) new_node.shift_after_node(last_node) last_node = new_node node.form = forms[0] node.lemma = lemmas[0] if node.misc['SpaceAfter'] == 'No': del node.misc['SpaceAfter'] last_node.misc['SpaceAfter'] = 'No'
Example #3
Source File: utils.py From icme2019 with MIT License | 6 votes |
def check_version(version): """Return version of package on pypi.python.org using json.""" def check(version): try: url_pattern = 'https://pypi.python.org/pypi/mdeepctr/json' req = requests.get(url_pattern) latest_version = parse('0') version = parse(version) if req.status_code == requests.codes.ok: j = json.loads(req.text.encode('utf-8')) releases = j.get('releases', []) for release in releases: ver = parse(release) if not ver.is_prerelease: latest_version = max(latest_version, ver) if latest_version > version: logging.warning('\nDeepCTR version {0} detected. Your version is {1}.\nUse `pip install -U mdeepctr` to upgrade.Changelog: https://github.com/shenweichen/DeepCTR/releases/tag/v{0}'.format( latest_version, version)) except Exception: return Thread(target=check, args=(version,)).start()
Example #4
Source File: data_loader.py From aospy with Apache License 2.0 | 6 votes |
def _maybe_cast_to_float64(da): """Cast DataArrays to np.float64 if they are of type np.float32. Parameters ---------- da : xr.DataArray Input DataArray Returns ------- DataArray """ if da.dtype == np.float32: logging.warning('Datapoints were stored using the np.float32 datatype.' 'For accurate reduction operations using bottleneck, ' 'datapoints are being cast to the np.float64 datatype.' ' For more information see: https://github.com/pydata/' 'xarray/issues/1346') return da.astype(np.float64) else: return da
Example #5
Source File: worker.py From neural-fingerprinting with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run_without_time_limit(self, cmd): """Runs docker command without time limit. Args: cmd: list with the command line arguments which are passed to docker binary Returns: how long it took to run submission in seconds Raises: WorkerError: if error occurred during execution of the submission """ cmd = [DOCKER_BINARY, 'run', DOCKER_NVIDIA_RUNTIME] + cmd logging.info('Docker command: %s', ' '.join(cmd)) start_time = time.time() retval = subprocess.call(cmd) elapsed_time_sec = long(time.time() - start_time) logging.info('Elapsed time of attack: %d', elapsed_time_sec) logging.info('Docker retval: %d', retval) if retval != 0: logging.warning('Docker returned non-zero retval: %d', retval) raise WorkerError('Docker returned non-zero retval ' + str(retval)) return elapsed_time_sec
Example #6
Source File: markbugs.py From udapi-python with GNU General Public License v3.0 | 6 votes |
def after_process_document(self, document): for lemma, _count in self.cop_count.most_common()[self.max_cop_lemmas:]: for node in self.cop_nodes[lemma]: self.log(node, 'cop-many-lemmas', 'deprel=cop but lemma=%s not in top-%d' % (lemma, self.max_cop_lemmas)) self.cop_count.clear() self.cop_nodes.clear() total = 0 message = 'ud.MarkBugs Error Overview:' for bug, count in sorted(self.stats.items(), key=lambda pair: (pair[1], pair[0])): total += count message += '\n%20s %10d' % (bug, count) message += '\n%20s %10d\n' % ('TOTAL', total) logging.warning(message) if self.save_stats: document.meta["bugs"] = message self.stats.clear()
Example #7
Source File: complywithtext.py From udapi-python with GNU General Public License v3.0 | 6 votes |
def solve_diffs(self, diffs, tree_chars, char_nodes, text): for diff in diffs: edit, tree_lo, tree_hi, text_lo, text_hi = diff # Focus only on edits of type 'replace', log insertions and deletions as failures. if edit == 'equal': continue if edit in ('insert', 'delete'): logging.warning('Unable to solve token-vs-text mismatch\n%s', _diff2str(diff, tree_chars, text)) continue # Revert the splittng and solve the diff. nodes = [n for n in char_nodes[tree_lo:tree_hi] if n is not None] form = text[text_lo:text_hi] self.solve_diff(nodes, form.strip())
Example #8
Source File: setspaceafterfromtext.py From udapi-python with GNU General Public License v3.0 | 6 votes |
def process_tree(self, root): text = root.text if text is None: raise ValueError('Tree %s has no text, cannot use ud.SetSpaceAfterFromText' % root) if text == root.compute_text(): return for node in root.token_descendants: if text.startswith(node.form): text = text[len(node.form):] if not text or text[0].isspace(): del node.misc['SpaceAfter'] text = text.lstrip() else: node.misc['SpaceAfter'] = 'No' else: logging.warning('Node %s does not match text "%s"', node, text[:20]) return if text: logging.warning('Extra text "%s" in tree %s', text, root)
Example #9
Source File: universal.py From xalpha with MIT License | 6 votes |
def decouple_code(code): """ decompose SH600000.A into SH600000, after :param code: :return: Tuple """ if len(code[1:].split(".")) > 1: # .SPI in US stock! type_ = code.split(".")[-1] code = ".".join(code.split(".")[:-1]) if type_.startswith("b") or type_.startswith("B"): type_ = "before" elif type_.startswith("a") or type_.startswith("A"): type_ = "after" elif type_.startswith("n") or type_.startswith("N"): type_ = "normal" else: logger.warning( "unrecoginzed flag for adjusted factor %s, use default" % type_ ) type_ = "before" else: type_ = "before" return code, type_
Example #10
Source File: installer.py From glazier with Apache License 2.0 | 6 votes |
def Run(self): file_name = str(self._args[0]) share = None if len(self._args) > 1: share = str(self._args[1]) logging.debug('Found log copy event for file %s to %s.', file_name, share) copier = log_copy.LogCopy() # EventLog try: copier.EventLogCopy(file_name) except log_copy.LogCopyError as e: logging.warning('Unable to complete log copy to EventLog. %s', e) # CIFS if share: try: copier.ShareCopy(file_name, share) except log_copy.LogCopyError as e: logging.warning('Unable to complete log copy via CIFS. %s', e)
Example #11
Source File: main.py From friendly-telegram with GNU Affero General Public License v3.0 | 6 votes |
def get_phones(arguments): """Get phones from the --token, --phone, and environment""" phones = set(arguments.phone if arguments.phone else []) phones.update(map(lambda f: f[18:-8], filter(lambda f: f.startswith("friendly-telegram-") and f.endswith(".session"), os.listdir(os.path.dirname(utils.get_base_dir()))))) authtoken = os.environ.get("authorization_strings", False) # for heroku if authtoken and not arguments.setup: try: authtoken = json.loads(authtoken) except json.decoder.JSONDecodeError: logging.warning("authtoken invalid") authtoken = False if arguments.setup or (arguments.tokens and not authtoken): authtoken = {} if arguments.tokens: for token in arguments.tokens: phone = sorted(phones).pop(0) phones.remove(phone) # Handled seperately by authtoken logic authtoken.update(**{phone: token}) return phones, authtoken
Example #12
Source File: gw_api.py From gw2pvo with MIT License | 6 votes |
def getActualKwh(self, date): payload = { 'powerstation_id' : self.system_id, 'count' : 1, 'date' : date.strftime('%Y-%m-%d') } data = self.call("v2/PowerStationMonitor/GetPowerStationPowerAndIncomeByDay", payload) if not data: logging.warning("GetPowerStationPowerAndIncomeByDay missing data") return 0 eday_kwh = 0 for day in data: if day['d'] == date.strftime('%m/%d/%Y'): eday_kwh = day['p'] return eday_kwh
Example #13
Source File: model.py From DOTA_models with Apache License 2.0 | 6 votes |
def _create_lstm_inputs(self, net): """Splits an input tensor into a list of tensors (features). Args: net: A feature map of shape [batch_size, num_features, feature_size]. Raises: AssertionError: if num_features is less than seq_length. Returns: A list with seq_length tensors of shape [batch_size, feature_size] """ num_features = net.get_shape().dims[1].value if num_features < self._params.seq_length: raise AssertionError('Incorrect dimension #1 of input tensor' ' %d should be bigger than %d (shape=%s)' % (num_features, self._params.seq_length, net.get_shape())) elif num_features > self._params.seq_length: logging.warning('Ignoring some features: use %d of %d (shape=%s)', self._params.seq_length, num_features, net.get_shape()) net = tf.slice(net, [0, 0, 0], [-1, self._params.seq_length, -1]) return tf.unstack(net, axis=1)
Example #14
Source File: ds_api.py From gw2pvo with MIT License | 6 votes |
def get_temperature_for_day(self, latitude, longitude, date): if latitude is None or longitude is None: return None data = { 'apiKey' : self.api_key, 'latitude' : latitude, 'longitude' : longitude, 'date' : date.strftime('%Y-%m-%d') + 'T00:00:00', } url = "https://api.darksky.net/forecast/{apiKey}/{latitude},{longitude},{date}?units=si&exclude=minutely,currently,daily,alerts,flags".format(**data) for i in range(1, 4): try: r = requests.get(url, timeout=10) r.raise_for_status() result = r.json() return result['hourly']['data'] except requests.exceptions.RequestException as arg: logging.warning(arg) time.sleep(i ** 3) else: logging.error("Failed to call DarkSky API")
Example #15
Source File: ds_api.py From gw2pvo with MIT License | 6 votes |
def get_temperature(self, latitude, longitude): if latitude is None or longitude is None: return None data = { 'apiKey' : self.api_key, 'latitude' : latitude, 'longitude' : longitude } url = "https://api.darksky.net/forecast/{apiKey}/{latitude},{longitude}?units=si&exclude=minutely,hourly,daily,alerts,flags".format(**data) for i in range(1, 4): try: r = requests.get(url, timeout=10) r.raise_for_status() result = r.json() return result['currently']['temperature'] except requests.exceptions.RequestException as arg: logging.warning(arg) time.sleep(i ** 3) else: logging.error("Failed to call DarkSky API")
Example #16
Source File: __main__.py From gw2pvo with MIT License | 6 votes |
def copy(settings): # Fetch readings from GoodWe date = datetime.strptime(settings.date, "%Y-%m-%d") gw = gw_api.GoodWeApi(settings.gw_station_id, settings.gw_account, settings.gw_password) data = gw.getDayReadings(date) if settings.pvo_system_id and settings.pvo_api_key: if settings.darksky_api_key: ds = ds_api.DarkSkyApi(settings.darksky_api_key) temperatures = ds.get_temperature_for_day(data['latitude'], data['longitude'], date) else: temperatures = None # Submit readings to PVOutput pvo = pvo_api.PVOutputApi(settings.pvo_system_id, settings.pvo_api_key) pvo.add_day(data['entries'], temperatures) else: for entry in data['entries']: logging.info("{}: {:6.0f} W {:6.2f} kWh".format( entry['dt'], entry['pgrid_w'], entry['eday_kwh'], )) logging.warning("Missing PVO id and/or key")
Example #17
Source File: client.py From microgear-python with ISC License | 6 votes |
def create(gearkey,gearsecret, appid="", args = {}): if 'debugmode' in args: logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%d/%m/%Y %I:%M:%S %p', ) else: logging.basicConfig(level=logging.WARNING, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%d/%m/%Y %I:%M:%S %p', ) microgear.gearalias = args.get('alias',"")[0:16] if 'scope' in args: matchScope = re.match( r'^(\w+:[a-zA-Z\/]+,*)+$', args['scope']) if matchScope: microgear.scope = args["scope"] else: microgear.scope = "" logging.warning("Specify scope is not valid") microgear.gearkey = gearkey microgear.gearsecret = gearsecret microgear.appid = appid
Example #18
Source File: client.py From microgear-python with ISC License | 6 votes |
def client_on_connect(client, userdata, rc): global block microgear.state = True logging.info("Connected with result code "+str(rc)) if rc == 0 : on_connect() auto_subscribeAndpublish() elif rc == 1 : logging.warning("Unable to connect: Incorrect protocol version.") elif rc == 2 : logging.warning("Unable to connect: Invalid client identifier.") elif rc == 3 : logging.warning("Unable to connect: Server unavailable.") elif rc == 4 : unsubscribe(current_id) microgear.mqtt_client.disconnect() on_info("Invalid credential.") logging.info("Unable to connect: Invalid credential, requesting new one") resettoken() connect(block_loop) elif rc == 5 : on_warning("Not authorised.") logging.warning("Unable to connect: Not authorised.") else: logging.warning("Unable to connect: Unknown reason")
Example #19
Source File: Logger.py From URS with MIT License | 6 votes |
def master_timer(function): def wrapper(*args): logging.info("INITIALIZING URS.") logging.info("") start = time.time() try: function(*args) except KeyboardInterrupt: print(Style.BRIGHT + Fore.RED + "\n\nURS ABORTED BY USER.\n") logging.warning("") logging.warning("URS ABORTED BY USER.\n") quit() logging.info("URS COMPLETED SCRAPES IN %.2f SECONDS.\n" % \ (time.time() - start)) return wrapper
Example #20
Source File: client.py From microgear-python with ISC License | 6 votes |
def resettoken(): cached = cache.get_item("microgear-"+microgear.gearkey+".cache") if cached : microgear.accesstoken = cached.get("accesstoken",{}) if "revokecode" in microgear.accesstoken : path = "/api/revoke/"+microgear.accesstoken["token"]+"/"+microgear.accesstoken["revokecode"] url = "" if microgear.securemode: url = "https://"+microgear.gearauthsite+":"+microgear.gearapisecureport+path; else: url = "http://"+microgear.gearauthsite+":"+microgear.gearapiport+path; response = requests.get(url) if response.status_code==200: cache.delete_item("microgear-"+microgear.gearkey+".cache") else: on_error("Reset token error.") logging.error("Reset token error.") else: cache.delete_item("microgear-"+microgear.gearkey+".cache") logging.warning("Token is still, please check your key on Key Management.") microgear.accesstoken = None
Example #21
Source File: utils.py From tpu_pretrain with Apache License 2.0 | 6 votes |
def init(args): # init logger log_format = '%(asctime)-10s: %(message)s' if args.log_file is not None and args.log_file != "": Path(args.log_file).parent.mkdir(parents=True, exist_ok=True) logging.basicConfig(level=logging.INFO, filename=args.log_file, filemode='w', format=log_format) logging.warning(f'This will get logged to file: {args.log_file}') else: logging.basicConfig(level=logging.INFO, format=log_format) # create output dir if args.output_dir.is_dir() and list(args.output_dir.iterdir()): logging.warning(f"Output directory ({args.output_dir}) already exists and is not empty!") assert 'bert' in args.output_dir.name, \ '''Output dir name has to contain `bert` or `roberta` for AutoModel.from_pretrained to correctly infer the model type''' args.output_dir.mkdir(parents=True, exist_ok=True) # set random seeds random.seed(args.seed) np.random.seed(args.seed) torch.manual_seed(args.seed)
Example #22
Source File: utils.py From harmony-ops with MIT License | 6 votes |
def get_logger(filename): logging.basicConfig(filename=f"{filename}", filemode='a', format="%(message)s") logging.warning(f"[{datetime.datetime.now()}] {'=' * 10}") def log(message, error=True): func = inspect.currentframe().f_back.f_code final_msg = "(%s:%i) %s" % ( func.co_name, func.co_firstlineno, message ) if error: logging.warning(final_msg) print(f"[ERROR] {final_msg}") else: print(final_msg) return log
Example #23
Source File: registry.py From glazier with Apache License 2.0 | 5 votes |
def remove_value(name: Text, root: Optional[Text] = 'HKLM', path: Optional[Text] = constants.REG_ROOT, use_64bit: Optional[bool] = constants.USE_REG_64, log: Optional[bool] = True): r"""Remove a registry value. Args: name: Registry value name. root: Registry root (HKCR\HKCU\HKLM\HKU). Defaults to HKLM. path: Registry key path. Defaults to constants.REG_ROOT. use_64bit: True for 64 bit registry. False for 32 bit. Defaults to constants.USE_REG_64. log: Log the registry operation to the standard logger. Defaults to True. """ try: reg = registry.Registry(root_key=root) reg.RemoveKeyValue( key_path=path, key_name=name, use_64bit=use_64bit) if log: logging.debug(r'Removed registry key: %s:\%s\%s', root, path, name) except registry.RegistryError as e: if e.errno == 2: logging.warning(r'Failed to delete non-existant registry key: %s:\%s\%s', root, path, name) else: raise Error(str(e))
Example #24
Source File: complywithtext.py From udapi-python with GNU General Public License v3.0 | 5 votes |
def _log_diffs(diffs, tree_chars, text, msg): if logging.getLogger().isEnabledFor(logging.DEBUG): logging.warning('=== After %s:', msg) for diff in diffs: logging.warning(_diff2str(diff, tree_chars, text))
Example #25
Source File: pvo_api.py From gw2pvo with MIT License | 5 votes |
def call(self, url, payload): logging.debug(payload) headers = { 'X-Pvoutput-Apikey' : self.m_api_key, 'X-Pvoutput-SystemId' : self.m_system_id, 'X-Rate-Limit': '1' } for i in range(1, 4): try: r = requests.post(url, headers=headers, data=payload, timeout=10) if 'X-Rate-Limit-Reset' in r.headers: reset = round(float(r.headers['X-Rate-Limit-Reset']) - time.time()) else: reset = 0 if 'X-Rate-Limit-Remaining' in r.headers: if int(r.headers['X-Rate-Limit-Remaining']) < 10: logging.warning("Only {} requests left, reset after {} seconds".format( r.headers['X-Rate-Limit-Remaining'], reset)) if r.status_code == 403: logging.warning("Forbidden: " + r.reason) time.sleep(reset + 1) else: r.raise_for_status() break except requests.exceptions.RequestException as arg: logging.warning(r.text or str(arg)) time.sleep(i ** 3) else: logging.error("Failed to call PVOutput API")
Example #26
Source File: unicorn_binance_websocket_api_manager.py From unicorn-binance-websocket-api with MIT License | 5 votes |
def start_monitoring_api(self, host='127.0.0.1', port=64201, warn_on_update=True): """ Start the monitoring API server :param host: listening ip address, use 0.0.0.0 or a specific address (default: 127.0.0.1) :type host: str :param port: listening port number (default: 64201) :type port: int :param warn_on_update: set to `False` to disable the update warning :type warn_on_update: bool """ thread = threading.Thread(target=self._start_monitoring_api_thread, args=(host, port, warn_on_update)) thread.start()
Example #27
Source File: unicorn_binance_websocket_api_manager.py From unicorn-binance-websocket-api with MIT License | 5 votes |
def _restart_stream(self, stream_id): """ This is NOT stop/start! Its purpose is to start a died stream again! Use `set_restart_request()` for stop/start! :param stream_id: id of a stream :type stream_id: uuid :return: stream_id or False """ try: if self.restart_requests[stream_id]['status'] != "new": logging.warning("BinanceWebSocketApiManager->_restart_stream() please use `set_restart_request() " "instead!") return False except KeyError: # no restart_request entry for this stream_id: logging.warning("BinanceWebSocketApiManager->_restart_stream() please use `set_restart_request() instead!") return False logging.info("BinanceWebSocketApiManager->_restart_stream(" + str(stream_id) + ", " + str(self.stream_list[stream_id]['channels']) + ", " + str(self.stream_list[stream_id]['markets']) + ")") self.restart_requests[stream_id] = {'status': "restarted"} self.restart_requests[stream_id]['last_restart_time'] = time.time() self.stream_list[stream_id]['status'] = "restarting" self.stream_list[stream_id]['kill_request'] = None self.stream_list[stream_id]['payload'] = [] loop = asyncio.new_event_loop() thread = threading.Thread(target=self._create_stream_thread, args=(loop, stream_id, self.stream_list[stream_id]['channels'], self.stream_list[stream_id]['markets'], self.stream_list[stream_id]['stream_label'], self.stream_list[stream_id]['stream_buffer_name'], True)) thread.start() return stream_id
Example #28
Source File: convert1to2.py From udapi-python with GNU General Public License v3.0 | 5 votes |
def after_process_document(self, document): """Print overall statistics of ToDo counts.""" message = 'ud.Convert1to2 ToDo Overview:' total = 0 for todo, count in sorted(self.stats.items(), key=lambda pair: (pair[1], pair[0])): total += count message += '\n%20s %10d' % (todo, count) message += '\n%20s %10d\n' % ('TOTAL', total) logging.warning(message) if self.save_stats: document.meta["todo"] = message self.stats.clear()
Example #29
Source File: fixneg.py From udapi-python with GNU General Public License v3.0 | 5 votes |
def process_node(self, node): if node.deprel == "neg": if node.upos == "PRON" and node.form == "ne": node.feats = 'Polarity=Neg' # delete other features elif node.upos != "ADJ": logging.warning("Strange node %s with deprel=neg", node) node.upos = "ADV" node.deprel = "advmod"
Example #30
Source File: f1.py From udapi-python with GNU General Public License v3.0 | 5 votes |
def process_end(self): # Redirect the default filehandle to the file specified by self.files self.before_process_document(None) if not self.visited_zones: logging.warning('Block eval.F1 was not applied to any zone. ' 'Check the parameter zones=%s', self.zones) elif len(self.visited_zones) > 1: logging.warning('Block eval.F1 was applied to more than one zone %s. ' 'The results are mixed together. Check the parameter zones=%s', list(self.visited_zones.elements()), self.zones) print('Comparing predicted trees (zone=%s) with gold trees (zone=%s), sentences=%d' % (next(self.visited_zones.elements()), self.gold_zone, self.visited_zones.most_common(1)[0][1])) if self.details: print('=== Details ===') print('%-10s %5s %5s %5s %6s %6s %6s' % ('token', 'pred', 'gold', 'corr', 'prec', 'rec', 'F1')) tokens = self._total.most_common(self.details) for token, _ in tokens: _prec = self._common[token] / (self._pred[token] or 1) _rec = self._common[token] / (self._gold[token] or 1) _f1 = 2 * _prec * _rec / ((_prec + _rec) or 1) print('%-10s %5d %5d %5d %6.2f%% %6.2f%% %6.2f%%' % (token, self._pred[token], self._gold[token], self._common[token], 100 * _prec, 100 * _rec, 100 * _f1)) print('=== Totals ===') print("%-9s = %7d\n" * 3 % ('predicted', self.pred, 'gold', self.gold, 'correct', self.correct), end='') pred, gold = self.pred or 1, self.gold or 1 # prevent division by zero precision = self.correct / pred recall = self.correct / gold f1 = 2 * precision * recall / ((precision + recall) or 1) print("%-9s = %6.2f%%\n" * 3 % ('precision', 100 * precision, 'recall', 100 * recall, 'F1', 100 * f1), end='') # difflib.SequenceMatcher does not compute LCS, so let's implement it here