本文整理汇总了Python中python_compat.set函数的典型用法代码示例。如果您正苦于以下问题:Python set函数的具体用法?Python set怎么用?Python set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, config, datasource_name):
BaseConsistencyProcessor.__init__(self, config, datasource_name)
self._check_url = config.get_enum(self._get_dproc_opt('check unique url'),
DatasetUniqueMode, DatasetUniqueMode.abort)
self._check_block = config.get_enum(self._get_dproc_opt('check unique block'),
DatasetUniqueMode, DatasetUniqueMode.abort)
(self._recorded_url, self._recorded_block) = (set(), set())
示例2: _getSubmissionJobs
def _getSubmissionJobs(self, maxsample):
# Get list of submittable jobs
readyList = self.jobDB.getJobs(ClassSelector(JobClass.READY))
retryOK = readyList
defaultJob = Job()
if self._job_retries >= 0:
retryOK = lfilter(lambda x: self.jobDB.get(x, defaultJob).attempt - 1 < self._job_retries, readyList)
modOK = lfilter(self._task.canSubmit, readyList)
jobList = set.intersection(set(retryOK), set(modOK))
if self._showBlocker and readyList and not jobList: # No submission but ready jobs
err = []
err += utils.QM((len(retryOK) > 0) and (len(modOK) == 0), [], ['have hit their maximum number of retries'])
err += utils.QM((len(retryOK) == 0) and (len(modOK) > 0), [], ['are vetoed by the task module'])
self._log_user_time.warning('All remaining jobs %s!', str.join(utils.QM(retryOK or modOK, ' or ', ' and '), err))
self._showBlocker = not (len(readyList) > 0 and len(jobList) == 0)
# Determine number of jobs to submit
submit = len(jobList)
if self._njobs_inqueue > 0:
submit = min(submit, self._njobs_inqueue - self.jobDB.getJobsN(ClassSelector(JobClass.ATWMS)))
if self._njobs_inflight > 0:
submit = min(submit, self._njobs_inflight - self.jobDB.getJobsN(ClassSelector(JobClass.PROCESSING)))
if self._continuous and (maxsample > 0):
submit = min(submit, maxsample)
submit = max(submit, 0)
if self._do_shuffle:
return self._sample(jobList, submit)
return sorted(jobList)[:submit]
示例3: _resync_psrc
def _resync_psrc(self):
activity = Activity('Performing resync of datasource %r' % self.get_datasource_name())
# Get old and new dataset information
provider_old = DataProvider.load_from_file(self._get_data_path('cache.dat'))
block_list_old = provider_old.get_block_list_cached(show_stats=False)
self._provider.clear_cache()
block_list_new = self._provider.get_block_list_cached(show_stats=False)
self._provider.save_to_file(self._get_data_path('cache-new.dat'), block_list_new)
# Use old splitting information to synchronize with new dataset infos
partition_len_old = self.get_parameter_len()
partition_changes = self._resync_partitions(
self._get_data_path('map-new.tar'), block_list_old, block_list_new)
activity.finish()
if partition_changes is not None:
# Move current splitting to backup and use the new splitting from now on
def _rename_with_backup(new, cur, old):
if self._keep_old:
os.rename(self._get_data_path(cur), self._get_data_path(old))
os.rename(self._get_data_path(new), self._get_data_path(cur))
_rename_with_backup('map-new.tar', 'map.tar', 'map-old-%d.tar' % time.time())
_rename_with_backup('cache-new.dat', 'cache.dat', 'cache-old-%d.dat' % time.time())
self._set_reader(DataSplitter.load_partitions(self._get_data_path('map.tar')))
self._log.debug('Dataset resync finished: %d -> %d partitions', partition_len_old, self._len)
(pnum_list_redo, pnum_list_disable) = partition_changes
return (set(pnum_list_redo), set(pnum_list_disable), partition_len_old != self._len)
示例4: getSubmissionJobs
def getSubmissionJobs(self, maxsample, static = {'showBlocker': True}):
# Get list of submittable jobs
readyList = self.jobDB.getJobs(ClassSelector(JobClass.READY))
retryOK = readyList
defaultJob = Job()
if self.maxRetry >= 0:
retryOK = filter(lambda x: self.jobDB.get(x, defaultJob).attempt - 1 < self.maxRetry, readyList)
modOK = filter(self._task.canSubmit, readyList)
jobList = set.intersection(set(retryOK), set(modOK))
if static['showBlocker'] and len(readyList) > 0 and len(jobList) == 0: # No submission but ready jobs
err = []
err += utils.QM(len(retryOK) > 0 and len(modOK) == 0, [], ['have hit their maximum number of retries'])
err += utils.QM(len(retryOK) == 0 and len(modOK) > 0, [], ['are vetoed by the task module'])
utils.vprint('All remaining jobs %s!' % str.join(utils.QM(retryOK or modOK, ' or ', ' and '), err), -1, True)
static['showBlocker'] = not (len(readyList) > 0 and len(jobList) == 0)
# Determine number of jobs to submit
submit = len(jobList)
if self.inQueue > 0:
submit = min(submit, self.inQueue - self.jobDB.getJobsN(ClassSelector(JobClass.ATWMS)))
if self.inFlight > 0:
submit = min(submit, self.inFlight - self.jobDB.getJobsN(ClassSelector(JobClass.PROCESSING)))
if self.continuous:
submit = min(submit, maxsample)
submit = max(submit, 0)
if self.doShuffle:
return self.sample(jobList, submit)
else:
return sorted(jobList)[:submit]
示例5: _resync
def _resync(self):
if self._data_provider:
activity = Activity('Performing resync of datasource %r' % self._name)
# Get old and new dataset information
ds_old = DataProvider.loadFromFile(self._getDataPath('cache.dat')).getBlocks(show_stats = False)
self._data_provider.clearCache()
ds_new = self._data_provider.getBlocks(show_stats = False)
self._data_provider.saveToFile(self._getDataPath('cache-new.dat'), ds_new)
# Use old splitting information to synchronize with new dataset infos
old_maxN = self._data_splitter.getMaxJobs()
jobChanges = self._data_splitter.resyncMapping(self._getDataPath('map-new.tar'), ds_old, ds_new)
activity.finish()
if jobChanges is not None:
# Move current splitting to backup and use the new splitting from now on
def backupRename(old, cur, new):
if self._keepOld:
os.rename(self._getDataPath(cur), self._getDataPath(old))
os.rename(self._getDataPath(new), self._getDataPath(cur))
backupRename( 'map-old-%d.tar' % time.time(), 'map.tar', 'map-new.tar')
backupRename('cache-old-%d.dat' % time.time(), 'cache.dat', 'cache-new.dat')
self._data_splitter.importPartitions(self._getDataPath('map.tar'))
self._maxN = self._data_splitter.getMaxJobs()
self._log.debug('Dataset resync finished: %d -> %d partitions', old_maxN, self._maxN)
return (set(jobChanges[0]), set(jobChanges[1]), old_maxN != self._maxN)
示例6: _get_possible_merge_categories
def _get_possible_merge_categories(self, map_cat2desc):
# Get dictionary with categories that will get merged when removing a variable
def _eq_dict(dict_a, dict_b, key):
# Merge parameters to reach category goal - NP hard problem, so be greedy and quick!
dict_a = dict(dict_a)
dict_b = dict(dict_b)
dict_a.pop(key)
dict_b.pop(key)
return dict_a == dict_b
var_key_result = {}
cat_key_search_dict = {}
for cat_key in map_cat2desc:
for var_key in map_cat2desc[cat_key]:
if var_key not in cat_key_search_dict:
cat_key_search = set(map_cat2desc.keys())
else:
cat_key_search = cat_key_search_dict[var_key]
if cat_key_search:
matches = lfilter(lambda ck: _eq_dict(map_cat2desc[cat_key],
map_cat2desc[ck], var_key), cat_key_search)
if matches:
cat_key_search_dict[var_key] = cat_key_search.difference(set(matches))
var_key_result.setdefault(var_key, []).append(matches)
return var_key_result
示例7: _resync_adapter
def _resync_adapter(self, pa_old, pa_new, result_redo, result_disable, size_change):
(map_jobnum2pnum, pspi_list_added, pspi_list_missing) = _diff_pspi_list(pa_old, pa_new,
result_redo, result_disable)
# Reorder and reconstruct parameter space with the following layout:
# NNNNNNNNNNNNN OOOOOOOOO | source: NEW (==self) and OLD (==from file)
# <same><added> <missing> | same: both in NEW and OLD, added: only in NEW, missing: only in OLD
if pspi_list_added:
_extend_map_jobnum2pnum(map_jobnum2pnum, pa_old.get_job_len(), pspi_list_added)
if pspi_list_missing:
# extend the parameter source by placeholders for the missing parameter space points
psrc_missing = _create_placeholder_psrc(pa_old, pa_new,
map_jobnum2pnum, pspi_list_missing, result_disable)
self._psrc = ParameterSource.create_instance('ChainParameterSource',
self._psrc_raw, psrc_missing)
self._map_jobnum2pnum = map_jobnum2pnum # Update Job2PID map
# Write resynced state
self._write_jobnum2pnum(self._path_jobnum2pnum + '.tmp')
ParameterSource.get_class('GCDumpParameterSource').write(self._path_params + '.tmp',
self.get_job_len(), self.get_job_metadata(), self.iter_jobs())
os.rename(self._path_jobnum2pnum + '.tmp', self._path_jobnum2pnum)
os.rename(self._path_params + '.tmp', self._path_params)
result_redo = result_redo.difference(result_disable)
if result_redo or result_disable:
map_pnum2jobnum = reverse_dict(self._map_jobnum2pnum)
def _translate_pnum(pnum):
return map_pnum2jobnum.get(pnum, pnum)
result_redo = set(imap(_translate_pnum, result_redo))
result_disable = set(imap(_translate_pnum, result_disable))
return (result_redo, result_disable, size_change)
return (set(), set(), size_change)
示例8: getCMSFiles
def getCMSFiles(self, blockPath):
lumiDict = {}
if self.selectedLumis: # Central lumi query
lumiDict = self.getCMSLumisImpl(blockPath)
lumiDict = QM(lumiDict, lumiDict, {})
for (fileInfo, listLumi) in self.getCMSFilesImpl(blockPath, self.onlyValid, self.selectedLumis):
if self.selectedLumis:
if not listLumi:
listLumi = lumiDict.get(fileInfo[DataProvider.URL], [])
def acceptLumi():
for (run, lumiList) in listLumi:
for lumi in lumiList:
if selectLumi((run, lumi), self.selectedLumis):
return True
if not acceptLumi():
continue
if self.includeLumi:
(listLumiExt_Run, listLumiExt_Lumi) = ([], [])
for (run, lumi_list) in sorted(listLumi):
for lumi in lumi_list:
listLumiExt_Run.append(run)
listLumiExt_Lumi.append(lumi)
fileInfo[DataProvider.Metadata] = [listLumiExt_Run, listLumiExt_Lumi]
else:
fileInfo[DataProvider.Metadata] = [list(sorted(set(map(lambda (run, lumi_list): run, listLumi))))]
yield fileInfo
示例9: _resync
def _resync(self): # This function is _VERY_ time critical!
tmp = self._psrc_raw.resync_psrc() # First ask about psrc changes
(result_redo, result_disable, size_change) = (set(tmp[0]), set(tmp[1]), tmp[2])
psrc_hash_new = self._psrc_raw.get_psrc_hash()
psrc_hash_changed = self._psrc_hash_stored != psrc_hash_new
self._psrc_hash_stored = psrc_hash_new
if not (result_redo or result_disable or size_change or psrc_hash_changed):
return ParameterSource.get_empty_resync_result()
ps_old = ParameterSource.create_instance('GCDumpParameterSource', self._path_params)
pa_old = ParameterAdapter(None, ps_old)
pa_new = ParameterAdapter(None, self._psrc_raw)
return self._resync_adapter(pa_old, pa_new, result_redo, result_disable, size_change)
示例10: getKeyMergeResults
def getKeyMergeResults():
varKeyResult = {}
catKeySearchDict = {}
for catKey in catDescDict:
for varKey in catDescDict[catKey]:
if varKey not in catKeySearchDict:
catKeySearch = set(catDescDict.keys())
else:
catKeySearch = catKeySearchDict[varKey]
if catKeySearch:
matches = filter(lambda ck: eqDict(catDescDict[catKey], catDescDict[ck], varKey), catKeySearch)
if matches:
catKeySearchDict[varKey] = catKeySearch.difference(set(matches))
varKeyResult.setdefault(varKey, []).append(matches)
return varKeyResult
示例11: _get_sandbox_file_list
def _get_sandbox_file_list(self, task, sm_list):
# Prepare all input files
dep_list = set(ichain(imap(lambda x: x.get_dependency_list(), [task] + sm_list)))
dep_fn_list = lmap(lambda dep: resolve_path('env.%s.sh' % dep,
lmap(lambda pkg: get_path_share('', pkg=pkg), os.listdir(get_path_pkg()))), dep_list)
task_config_dict = dict_union(self._remote_event_handler.get_mon_env_dict(),
*imap(lambda x: x.get_task_dict(), [task] + sm_list))
task_config_dict.update({'GC_DEPFILES': str.join(' ', dep_list),
'GC_USERNAME': self._token.get_user_name(), 'GC_WMS_NAME': self._name})
task_config_str_list = DictFormat(escape_strings=True).format(
task_config_dict, format='export %s%s%s\n')
vn_alias_dict = dict(izip(self._remote_event_handler.get_mon_env_dict().keys(),
self._remote_event_handler.get_mon_env_dict().keys()))
vn_alias_dict.update(task.get_var_alias_map())
vn_alias_str_list = DictFormat(delimeter=' ').format(vn_alias_dict, format='%s%s%s\n')
# Resolve wildcards in task input files
def _get_task_fn_list():
for fpi in task.get_sb_in_fpi_list():
matched = glob.glob(fpi.path_abs)
if matched != []:
for match in matched:
yield match
else:
yield fpi.path_abs
return lchain([self._remote_event_handler.get_file_list(), dep_fn_list, _get_task_fn_list(), [
VirtualFile('_config.sh', sorted(task_config_str_list)),
VirtualFile('_varmap.dat', sorted(vn_alias_str_list))]])
示例12: main
def main(opts, args):
config = get_dataset_config(opts, args)
provider = config.getPlugin('dataset', cls = DataProvider)
blocks = provider.getBlocks()
if len(blocks) == 0:
raise DatasetError('No blocks!')
datasets = set(imap(itemgetter(DataProvider.Dataset), blocks))
if len(datasets) > 1 or opts.info:
headerbase = [(DataProvider.Dataset, 'Dataset')]
else:
print('Dataset: %s' % blocks[0][DataProvider.Dataset])
headerbase = []
if opts.list_datasets:
list_datasets(blocks)
if opts.list_blocks:
list_blocks(blocks, headerbase)
if opts.list_files:
list_files(datasets, blocks)
if opts.list_storage:
list_storage(blocks, headerbase)
if opts.metadata and not opts.save:
list_metadata(datasets, blocks)
if opts.block_metadata and not opts.save:
list_block_metadata(datasets, blocks)
if opts.config_entry:
list_config_entries(opts, blocks, provider)
if opts.info:
list_infos(blocks)
if opts.save:
save_dataset(opts, provider)
示例13: logging_setup
def logging_setup(config):
if config.getBool('debug mode', False, onChange = None):
config.set('level', 'NOTSET', '?=')
config.set('detail lower limit', 'NOTSET')
config.set('detail upper limit', 'NOTSET')
config.set('abort handler', 'stdout debug_file', '?=')
config.setInt('abort code context', 2)
config.setInt('abort variables', 2)
config.setInt('abort file stack', 2)
config.setInt('abort tree', 2)
display_logger = config.getBool('display logger', False, onChange = None)
# Find logger names in options
logger_names = set()
for option in config.getOptions():
if option in ['debug mode', 'display logger']:
pass
elif option.count(' ') == 0:
logger_names.add('')
else:
logger_names.add(option.split(' ')[0].strip())
logger_names = sorted(logger_names)
logger_names.reverse()
for logger_name in logger_names:
logging_create_handlers(config, logger_name)
if display_logger:
dump_log_setup(logging.WARNING)
示例14: _get_workflow_graph
def _get_workflow_graph(workflow):
(graph, node_list) = _get_graph(workflow)
# Process nodes
node_str_list = []
map_node2name = {}
map_node2color = {}
for node in sorted(node_list, key=lambda x: x.__class__.__name__):
node_props = {
'label': '"%s"' % _get_node_label(node),
'fillcolor': '"%s"' % _get_node_color(node, map_node2color),
'style': '"filled"',
}
if node == workflow:
node_props['root'] = 'True'
node_prop_str = str.join('; ', imap(lambda key: '%s = %s' % (key, node_props[key]), node_props))
node_str_list.append('%s [%s];\n' % (_get_node_name(node, map_node2name), node_prop_str))
# Process edges
edge_str_list = []
for entry in sorted(graph, key=lambda x: x.__class__.__name__):
for child in sorted(set(graph[entry]), key=lambda x: x.__class__.__name__):
edge_str_list.append('%s -> %s;\n' % (_get_node_name(entry, map_node2name),
_get_node_name(child, map_node2name)))
cluster_str_list = []
dot_header = 'digraph mygraph {\nmargin=0;\nedge [len=2];\noverlap=compress;splines=True;\n'
dot_format_string_list = [dot_header] + node_str_list + cluster_str_list + edge_str_list + ['}\n']
return str.join('', dot_format_string_list)
示例15: _get_graph
def _get_graph(instance, graph=None, visited=None):
graph = graph or {}
children = _get_instance_children(instance)
visited = visited or set()
for child in children:
child_module = ''
if hasattr(child, '__module__'):
child_module = child.__module__ or ''
child_name = ''
if hasattr(child, '__name__'):
child_name = child.__name__ or ''
child_class_name = child.__class__.__name__ or ''
if 'grid_control' not in child_module:
continue
if 'testsuite' in child_name:
continue
if not issubclass(child.__class__, Plugin):
continue
if child_class_name in ['instancemethod', 'function', 'type', 'method-wrapper']:
continue
if child in (None, True, False):
continue
graph.setdefault(instance, []).append(child)
if child not in visited:
visited.add(child)
_get_graph(child, graph, visited)
return (graph, list(visited))