本文整理汇总了Python中sys._getframe函数的典型用法代码示例。如果您正苦于以下问题:Python _getframe函数的具体用法?Python _getframe怎么用?Python _getframe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_getframe函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: update_newdevice
def update_newdevice(self,res):
'''添加新的小机到数据库'''
dbcon = QueryDB().get_dbconn()
mirco_devices = QueryDB.get_devices_table(res.vendor)
if not mirco_devices.exists(engine):
mirco_devices.create(engine)
s = sql.select([mirco_devices.c.devid]).where(mirco_devices.c.devid == res.tuid)
row = ''
try:
result = dbcon.execute(s)
row = result.fetchall()
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
ipadr = int(binascii.hexlify(socket.inet_aton(res.host[0])),16) & 0xFFFFFFFF
ipprt = res.host[1] & 0xFFFF
#print "host %d:%d" % (ipadr,ipprt)
data = ''
if res.attrs.has_key(STUN_ATTRIBUTE_DATA):
data = res.attrs[STUN_ATTRIBUTE_DATA][-1]
if not row: # 找不到这个UUID 就插入新的
ins = mirco_devices.insert().values(devid=res.tuid,is_active=True,
is_online=True,chost=[ipadr,ipprt],data=data,last_login_time=datetime.now())
try:
result = dbcon.execute(ins)
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
#print "insert new devices result fetchall"
else:
upd = mirco_devices.update().values(is_online=True,chost = [ipadr,ipprt],data=data,
last_login_time=datetime.now()).where(mirco_devices.c.devid == res.tuid)
try:
result = dbcon.execute(upd)
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
开发者ID:yjdwbj,项目名称:python-examples,代码行数:35,代码来源:epoll_mp_srv.py
示例2: find_chain
def find_chain(obj, predicate, edge_func, max_depth=20, extra_ignore=()):
queue = [obj]
depth = {id(obj): 0}
parent = {id(obj): None}
ignore = set(extra_ignore)
ignore.add(id(extra_ignore))
ignore.add(id(queue))
ignore.add(id(depth))
ignore.add(id(parent))
ignore.add(id(ignore))
ignore.add(id(sys._getframe())) # this function
ignore.add(id(sys._getframe(1))) # find_chain/find_backref_chain, most likely
gc.collect()
while queue:
target = queue.pop(0)
if predicate(target):
chain = [target]
while parent[id(target)] is not None:
target = parent[id(target)]
chain.append(target)
return chain
tdepth = depth[id(target)]
if tdepth < max_depth:
referrers = edge_func(target)
ignore.add(id(referrers))
for source in referrers:
if id(source) in ignore:
continue
if id(source) not in depth:
depth[id(source)] = tdepth + 1
parent[id(source)] = target
queue.append(source)
return [obj] # not found
开发者ID:Eronarn,项目名称:objgraph,代码行数:33,代码来源:objgraph.py
示例3: write_hash_manifests
def write_hash_manifests(self):
if not self.manifests_updated:
return False
today = datetime.datetime.strftime(
datetime.datetime.now(), "%Y%m%d%H%M%S")
for alg in set(self.algorithms):
manifest_path = os.path.join(self.path, 'manifest-{}.txt'.format(alg))
copy_manifest_path = os.path.join(self.path, 'manifest-{}-{}.old'.format(alg, today))
try:
shutil.copyfile(manifest_path, copy_manifest_path)
except:
LOGGER.error("Do not have permission to write new manifests")
else:
self.add_premisevent(process = "Copy Bag Manifest",
msg = "{} copied to {} before writing new manifest".format(
os.path.basename(manifest_path),
os.path.basename(copy_manifest_path)),
outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)
try:
with open(manifest_path, 'w') as manifest:
for payload_file, hashes in self.entries.items():
if payload_file.startswith("data" + os.sep):
manifest.write("{} {}\n".format(hashes[alg], bagit._encode_filename(payload_file)))
except:
LOGGER.error("Do not have permission to overwrite hash manifests")
else:
LOGGER.info("{} written".format(manifest_path))
self.add_premisevent(process = "Write Bag Manifest",
msg = "{} written as a result of new or updated payload files".format(
os.path.basename(manifest_path)),
outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)
return True
开发者ID:NYPL,项目名称:ami-tools,代码行数:35,代码来源:update_bag.py
示例4: find_diff
def find_diff(self):
"""
Find the difference between the set from mySQL and ip network namespace.
"""
count = 0
try:
for agent in self.agents:
in_agent = [x for x in self.net_in_agent[agent] if x not in self.net_in_ns[agent]]
in_ns = [x for x in self.net_in_ns[agent] if x not in self.net_in_agent[agent]]
if len(in_agent) + len(in_ns) > 0:
print("DHCP agent in %s:" % self.agents[agent]['host'])
for net in in_agent:
if net in self.networks:
print(" %s %s is in mySQL but not in ip-netns" %
(net, self.networks[net]))
else:
print(" %s is in mySQL but not in net-list" % net)
count = count + 1
for net in in_ns:
if net in self.networks:
print(" %s %s is in ip-netns but not in mySQL" %
(net, self.networks[net]))
else:
print(" %s is in ip-netns but not in net-list" % net)
count = count + 1
except:
logger.warning("%s:%s() %d: %s %s", self.__class__.__name__,
sys._getframe().f_code.co_name, sys._getframe().f_lineno,
sys.exc_info()[0], sys.exc_info()[1])
raise
finally:
print("Found %d discrepancies in network-to-agent between mySQL and IP network namespace" % count)
开发者ID:yeungp,项目名称:OpenStack-tools,代码行数:32,代码来源:neutron_tools.py
示例5: __init__
def __init__(self, depth=1, moduleLevel = False, allowed_scope=None):
scope, module, f_locals, f_globals, codeinfo = \
getFrameInfo(sys._getframe(depth+1))
if allowed_scope and scope not in allowed_scope:
raise TypeError("This directive is not allowed "
"to run in this scope: %s"%scope)
if scope == 'module':
self.name = f_locals['__name__']
else:
self.name = codeinfo[2]
self.locals = f_locals
self.scope = scope
self.module = module
self.codeinfo = codeinfo
api.mods.add(self.module.__name__)
if depth > 1:
_, mod, _, _, ci = getFrameInfo(sys._getframe(2))
self.hash = (module.__name__, codeinfo[1], mod.__name__, ci[1])
else:
self.hash = (module.__name__, codeinfo[1])
开发者ID:blaflamme,项目名称:ptah,代码行数:25,代码来源:directives.py
示例6: stop_download
def stop_download(download_id):
log.log(__name__, sys._getframe().f_code.co_name, 'download_id %d' % download_id, log.LEVEL_DEBUG)
download_to_stop = ManageDownload.get_download_by_id(download_id)
log.log(__name__, sys._getframe().f_code.co_name, 'download to stop %s' % (download_to_stop.to_string()), log.LEVEL_DEBUG)
ManageDownload.stop_download(download_to_stop)
开发者ID:capic,项目名称:plow_pyhton,代码行数:7,代码来源:treatment.py
示例7: pl
def pl(value):
print sys._getframe().f_code.co_name
print 'value'
print type(value)
print value
print 'length: ' + str( len(value))
sys.exit('X')
开发者ID:ashish2,项目名称:spidy,代码行数:7,代码来源:pricedealsindia_spider.py
示例8: send_events_local
def send_events_local():
global results
client = MongoClient()
mongodb = client[MONGODB_NAME]
start_time = time.time()
valid_events = 0
# Store raw event information
for event in results:
#entry = {}
#for key in event.keys():
# entry[key] = event[key]
# flag indicating whether this item has been processed.
# entry["processed"] = 0
event["processed"] = 0
collection = mongodb[EVENTS_COL]
# get a list of event types to keep:
# everything that starts with EVT defined in common.py
temp_list = [CONF[key] for key in CONF if key.startswith("EVT")]
events_type_list = list(chain(*temp_list))
if get_prop(event, "TYPE_EVENT") in events_type_list:
collection.insert(event)
valid_events += 1
print "=========== INCOMING EVENTS", len(results), "total,", valid_events, "valid. ============="
print sys._getframe().f_code.co_name, "COMPLETED", (time.time() - start_time), "seconds"
开发者ID:jinhan,项目名称:LectureScapeBlock,代码行数:25,代码来源:send_event.py
示例9: test_catch_unknown_pairs
def test_catch_unknown_pairs(self):
print sys._getframe().f_code.co_name
pdb_id = '3a3w'
nob_out = nbo.run(pdb_id)
expected = [pdb_id] + ['-2']*3
expected = ','.join(expected)
self.assertEqual(nob_out[:len(expected)],expected)
开发者ID:youdar,项目名称:work,代码行数:7,代码来源:test_nonbonded_ovelap_collection.py
示例10: me_him
def me_him(self,value,color="purple"):
"""
me_him - determines current function prepends class name and displays caller function
"""
if self.output_caller:
self.color="".join(color)
self._me="".join(sys._getframe(1).f_code.co_name)
self._him="".join(sys._getframe(2).f_code.co_name)
self._me_him="".join(value)+"."+self._me+self.colors['default']+self._him+"\x1b[00m"
self._lineno=inspect.currentframe().f_back.f_lineno
if self.colors_active:
try:
if self.colors[color] and self.has_colors:
if self.show_lineno_caller:
if self.break_all:
sys.stdout.write("\n"+str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m\n")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
if self.break_all:
sys.stdout.write("\n"+self.colors[self.color] + self._me_him + "\x1b[00m\n")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(self.colors[self.color] + self._me_him + "\x1b[00m")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(self._me_him)
except (KeyError, e):
sys.stdout.write(self._me_him)
else:
sys.stdout.write(self._me_him)
开发者ID:gxela,项目名称:pynutbutter,代码行数:33,代码来源:stdout_colours.py
示例11: _find
def _find(self, name, type_=CausalSpace):
try:
for frame in range(0,63):
if name in sys._getframe(frame).f_locals:
if isinstance(sys._getframe(frame).f_locals[name], type_):
return sys._getframe(frame).f_locals[name]
except:pass
开发者ID:migacollabs,项目名称:Pyaella,代码行数:7,代码来源:causal.py
示例12: debug
def debug(f):
if zen_settings.get('debug'):
# sublime.log_commands(True)
frame = sys._getframe(1)
if 'debug' in frame.f_code.co_name : frame = sys._getframe(2)
line = frame.f_lineno
print 'debug:ZenCoding.%s:%s:' % (__name__, line), f
开发者ID:NoelDavies,项目名称:st2config,代码行数:7,代码来源:sublimezenplugin.py
示例13: _merge_psi4_qcel_apis
def _merge_psi4_qcel_apis(args, kwargs):
"""Outer shim to allow both Psi4-style and QCA-style testing interfaces through the same function.
Notes
-----
`kwargs` modified (and returned) in-place
"""
def process_digits(digits):
if digits >= 1:
return 10**-digits
return digits
if len(args) == 0:
kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name
elif len(args) == 1:
if isinstance(args[0], str):
kwargs['label'] = args[0]
else:
kwargs['atol'] = process_digits(args[0])
kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name
if 'verbose' in kwargs:
kwargs['quiet'] = (kwargs.pop('verbose') < 1)
elif len(args) == 2:
kwargs['atol'] = process_digits(args[0])
kwargs['label'] = args[1]
if 'verbose' in kwargs:
kwargs['quiet'] = (kwargs.pop('verbose') < 1)
else:
raise ValueError("""Not following either Psi4 or QCElemental API pattern for comparison.""")
开发者ID:psi4,项目名称:psi4,代码行数:35,代码来源:testing.py
示例14: get_plugin_source
def get_plugin_source(module=None, stacklevel=None):
"""Returns the :class:`PluginSource` for the current module or the given
module. The module can be provided by name (in which case an import
will be attempted) or as a module object.
If no plugin source can be discovered, the return value from this method
is `None`.
This function can be very useful if additional data has been attached
to the plugin source. For instance this could allow plugins to get
access to a back reference to the application that created them.
:param module: optionally the module to locate the plugin source of.
:param stacklevel: defines how many levels up the module should search
for before it discovers the plugin frame. The
default is 0. This can be useful for writing wrappers
around this function.
"""
if module is None:
frm = sys._getframe((stacklevel or 0) + 1)
name = frm.f_globals['__name__']
glob = frm.f_globals
elif isinstance(module, string_types):
frm = sys._getframe(1)
name = module
glob = __import__(module, frm.f_globals,
frm.f_locals, ['__dict__']).__dict__
else:
name = module.__name__
glob = module.__dict__
return _discover_space(name, glob)
开发者ID:mitsuhiko,项目名称:pluginbase,代码行数:31,代码来源:pluginbase.py
示例15: unpacktype
def unpacktype(binstr, member, mtype):
offset = member[1]
size = member[2]
fmt = ''
if mtype == STR:
fmt = str(size) + 's'
elif mtype == INT:
fmt = 'I' if size == 4 else 'Q'
elif mtype == SHT:
fmt = 'H'
else:
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack the unknown type %d.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, mtype))
return None
if struct.calcsize(fmt) != len(binstr[offset:size + offset]):
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack '%s' (fmt size: %d) from %d bytes.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, fmt, struct.calcsize(fmt),
len(binstr[offset:size + offset])))
return None
return struct.unpack(fmt, binstr[offset:size + offset])[0]
开发者ID:Im-Mr-Chris,项目名称:volafox,代码行数:25,代码来源:dumpcomppage.py
示例16: test_catch_multiple_models
def test_catch_multiple_models(self):
print sys._getframe().f_code.co_name
pdb_id = '203d'
nob_out = nbo.run(pdb_id)
expected = [pdb_id] + ['-3']*3
expected = ','.join(expected)
self.assertEqual(nob_out[:len(expected)],expected)
开发者ID:youdar,项目名称:work,代码行数:7,代码来源:test_nonbonded_ovelap_collection.py
示例17: allow_self_input_http
def allow_self_input_http(blackholing, domainname):
if blackholing == True:
proc = subprocess.Popen(
"ifconfig | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | uniq | grep -v %s"
% current_ip(domainname),
shell=True,
stdout=subprocess.PIPE,
)
else:
proc = subprocess.Popen(
"ifconfig | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | uniq", shell=True, stdout=subprocess.PIPE
)
stdout_str = proc.stdout.read()
vps_ips = return_ips(stdout_str, sys._getframe().f_code.co_name)
for vps_ip in vps_ips:
if blackholing == True:
proc2 = subprocess.Popen(
"/sbin/iptables -A INPUT -s {0} -p tcp -m multiport --dport 80,443 -j ACCEPT".format(vps_ip),
shell=True,
stdout=subprocess.PIPE,
)
else:
proc2 = subprocess.Popen(
"/sbin/iptables -A INPUT -s {0} -p tcp -m multiport --dport 80,443 -j ACCEPT".format(vps_ip),
shell=True,
stdout=subprocess.PIPE,
)
proc_check(proc2, sys._getframe().f_code.co_name)
开发者ID:SmartEternity,项目名称:iptables_builder,代码行数:28,代码来源:iptables_builder.py
示例18: test_catch_bad_cryst1
def test_catch_bad_cryst1(self):
print sys._getframe().f_code.co_name
pdb_id = '2bvb'
nob_out = nbo.run(pdb_id)
expected = [pdb_id] + ['-4']*3
expected = ','.join(expected)
self.assertEqual(nob_out[:len(expected)],expected)
开发者ID:youdar,项目名称:work,代码行数:7,代码来源:test_nonbonded_ovelap_collection.py
示例19: _d
def _d(msg, *args):
"""
Format a debug log message. This function will automatically append calling function name and file/line number.
:Parameters:
- `msg` : Log message formatted using the Python `formatter class <https://docs.python.org/2/library/string.html#custom-string-formatting>`_.
- `args` : Message arguments.
:Usage:
Log an integer or a float variable.
.. code-block:: python
_d("Var x has value {0}", x)
_d("Var y is a float with value {0:0.2f} to 2 decimal places.", y)
"""
frame1=sys._getframe(1)
frame2=sys._getframe(2)
n=len(args)
m1="{0} ({{{1}}}:{{{2}}}:{{{3}}}:{{{4}}})".format(msg,n, n+1, n+2, n+3)
a1=list(args)+[frame1.f_code.co_name, frame2.f_code.co_name, frame2.f_code.co_filename, frame2.f_lineno]
return m1.format(*a1)
开发者ID:forstater,项目名称:mosaic,代码行数:27,代码来源:mosaicLogFormat.py
示例20: get_netns
def get_netns(self):
"""
Get all the network namespace in each network node.
"""
count = 0
start = time.time()
try:
for agent in self.agents:
c = "ssh %s -o 'StrictHostKeyChecking=no' 'ip netns | grep qdhcp'" % (
self.agents[agent]['host'])
pipe = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout
for line in pipe:
s = line.strip().split('qdhcp-')
self.net_in_ns[agent].append(s[1])
count = count + 1
except:
logger.warning("%s:%s() %d: %s %s", self.__class__.__name__,
sys._getframe().f_code.co_name, sys._getframe().f_lineno,
sys.exc_info()[0], sys.exc_info()[1])
raise
finally:
duration = time.time() - start
logger.info("%s:%s() %d: found %d IP network namespace in %.3f seconds",
self.__class__.__name__,
sys._getframe().f_code.co_name, sys._getframe().f_lineno,
count, duration)
开发者ID:yeungp,项目名称:OpenStack-tools,代码行数:26,代码来源:neutron_tools.py
注:本文中的sys._getframe函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论