• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python threadframe.dict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中threadframe.dict函数的典型用法代码示例。如果您正苦于以下问题:Python dict函数的具体用法?Python dict怎么用?Python dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dict函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: print_nonsleeping

        def print_nonsleeping( self, threads_object_dict ):
            print >> self.file_nonsleeping, "Non-Sleeping threads at %s:" % time.asctime()
            print >> self.file_nonsleeping
            all_threads_are_sleeping = True
            threads = get_current_thread_object_dict()
            for thread_id, frame in threadframe.dict().iteritems():
                if thread_id in threads:
                    object = repr( threads[thread_id] )
                else:
                    object = "<No Thread object>"
                tb = traceback.extract_stack(frame)
                if self.thread_is_sleeping(tb[-1]):
                    if thread_id in self.nonsleeping_heartbeats:
                        del self.nonsleeping_heartbeats[thread_id]
                    continue

                # Count non-sleeping thread heartbeats
                if thread_id in self.nonsleeping_heartbeats:
                    self.nonsleeping_heartbeats[thread_id] += 1
                else:
                    self.nonsleeping_heartbeats[thread_id]=1

                good_frame = self.get_interesting_stack_frame(tb)
                print >> self.file_nonsleeping, "Thread %s\t%s\tnon-sleeping for %d heartbeat(s)\n  File %s:%d\n    Function \"%s\"\n      %s" % \
                        ( thread_id, object, self.nonsleeping_heartbeats[thread_id], good_frame[0], good_frame[1], good_frame[2], good_frame[3] )
                all_threads_are_sleeping = False

            if all_threads_are_sleeping:
                print >> self.file_nonsleeping, "All threads are sleeping."
            print >> self.file_nonsleeping
            self.file_nonsleeping.flush()
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:31,代码来源:heartbeat.py


示例2: run

 def run( self ):
     self.file = open( self.fname, "a" )
     print >> self.file, "Heartbeat for pid %d thread started at %s" % ( self.pid, time.asctime() )
     print >> self.file
     self.file_nonsleeping = open ( self.fname_nonsleeping, "a" )
     print >> self.file_nonsleeping, "Non-Sleeping-threads for pid %d thread started at %s" % ( self.pid, time.asctime() )
     print >> self.file_nonsleeping
     try:
         while not self.should_stop:
             # Print separator with timestamp
             print >> self.file, "Traceback dump for all threads at %s:" % time.asctime()
             print >> self.file
             # Print the thread states
             threads = get_current_thread_object_dict()
             for thread_id, frame in threadframe.dict().iteritems():
                 if thread_id in threads:
                     object = repr( threads[thread_id] )
                 else:
                     object = "<No Thread object>"
                 print >> self.file, "Thread %s, %s:" % ( thread_id, object )
                 print >> self.file
                 traceback.print_stack( frame, file=self.file )
                 print >> self.file
             print >> self.file, "End dump"
             print >> self.file
             self.file.flush()
             self.print_nonsleeping(threads)
             # Sleep for a bit
             self.wait_event.wait( self.period )
     finally:
         print >> self.file, "Heartbeat for pid %d thread stopped at %s" % ( self.pid, time.asctime() )
         print >> self.file
         # Cleanup
         self.file.close()
         self.file_nonsleeping.close()
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:35,代码来源:heartbeat.py


示例3: print_stacks

def print_stacks():
    while True:
        print '=' * 72
        for id,frame in threadframe.dict().iteritems():
            print '----- [%s] ------' % id
            print_stack(frame)
        time.sleep(10)
开发者ID:ronaldahmed,项目名称:robot-navigation,代码行数:7,代码来源:pendulum.py


示例4: dump

    def dump(self):
        try:
            stacks = sys._current_frames()
        except AttributeError:
            try:
                stacks = threadframe.dict()
            except:
                self.logger.debug("Stack dumping not supported")
                return

        for (id, stack) in stacks.items():
            msg = "Stack trace for thread %i\n" % id
            msg = msg + ''.join(traceback.format_stack(stack))
            self.logger.debug(msg)
开发者ID:BillTheBest,项目名称:mom,代码行数:14,代码来源:StackDumper.py


示例5: dump_threads

def dump_threads():
    """Dump running threads

    Returns a string with the tracebacks.
    """
    res = []
    frames = threadframe.dict()
    this_thread_id = thread.get_ident()

    for thread_id, frame in frames.iteritems():
        if thread_id == this_thread_id:
            continue
        # Find request in frame
        reqinfo = ['']
        f = frame
        while f is not None:
            co = f.f_code
            if co.co_filename.endswith('Publish.py'):
                request = f.f_locals.get('request')
                if request is not None:
                    method = request.get('REQUEST_METHOD', '')
                    path = request.get('PATH_INFO', '')
                    url = request.get('URL', '')
                    agent = request.get('HTTP_USER_AGENT', '')
                    query_string = request.get('QUERY_STRING')

                    query = 'QUERY: %s %s' % (method, path)
                    if query_string is not None:
                        query += '?%s' % query_string

                    reqinfo.append(query)
                    reqinfo.append('URL: %s' % url)
                    reqinfo.append('HTTP_USER_AGENT: %s' % agent)
                    break
            f = f.f_back

        output = StringIO()
        traceback.print_stack(frame, file=output)
        output = output.getvalue()

        lines = [line.strip() for line in output.split('\n') if line.strip() != '']
        zeo_marker = os.path.join('ZEO', 'zrpc', 'connection')
        acquire_marker = 'l.acquire()'
        if len(lines) > 1 and (zeo_marker in lines[-2] or acquire_marker in lines[-1]):
            output = None

        res.append((thread_id, reqinfo, output))
    return res
开发者ID:eea,项目名称:ZopeHealthWatcher,代码行数:48,代码来源:dumper.py


示例6: dump_threads

def dump_threads():
    """Dump running threads

    Returns a string with the tracebacks.
    """
    frames = threadframe.dict()
    this_thread_id = thread.get_ident()
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    res = ["Threads traceback dump at %s\n" % now]
    for thread_id, frame in frames.iteritems():
        if thread_id == this_thread_id:
            continue

        # Find request in frame
        reqinfo = ''
        f = frame
        while f is not None:
            co = f.f_code
            if (co.co_name == 'publish' and
                co.co_filename.endswith('/ZPublisher/Publish.py')):
                request = f.f_locals.get('request')
                if request is not None:
                    reqinfo = (request.get('REQUEST_METHOD', '') + ' ' +
                               request.get('PATH_INFO', ''))
                    qs = request.get('QUERY_STRING')
                    if qs:
                        reqinfo += '?'+qs
                break
            f = f.f_back
        if reqinfo:
            reqinfo = " (%s)" % reqinfo

        output = StringIO()
        traceback.print_stack(frame, file=output)
        res.append("Thread %s%s:\n%s" %
            (thread_id, reqinfo, output.getvalue()))

    frames = None
    res.append("End of dump")
    result = '\n'.join(res)
    if isinstance(result, unicode):
      result = result.encode('utf-8')
    return result
开发者ID:smetsjp,项目名称:erp5,代码行数:43,代码来源:dumper.py


示例7: dumpThreads

    def dumpThreads(self):
        """Display all different traceback of Threads for debugging.

        Require threadframe module."""
        import threadframe
        stacks = {}
        frames = threadframe.dict()
        for thread_id, frame in frames.iteritems():
            stack = ''.join(traceback.format_stack(frame))
            stacks[stack] = stacks.setdefault(stack, []) + [thread_id]
        def sort_stack(x, y):
            """sort stack by number of thread."""
            return cmp(len(x[1]), len(y[1]))
        stacks = stacks.items()
        stacks.sort(sort_stack)
        for stack, thread_ids in stacks:
            trace('=' * 72 + '\n')
            trace('%i threads : %s\n' % (len(thread_ids), str(thread_ids)))
            trace('-' * 72 + '\n')
            trace(stack + '\n')
开发者ID:jasongrout,项目名称:FunkLoad,代码行数:20,代码来源:BenchRunner.py


示例8: threadDump

	def threadDump(signum, frame):
		"""Signal handler for dumping thread stack frames to stdout."""
		print
		print "App server has been signaled to attempt a thread dump."
		print
		print "Thread stack frame dump at", asclocaltime()
		sys.stdout.flush()
		frames = threadframe.dict()
		items = frames.items()
		items.sort()
		print
		print "-" * 79
		print
		for threadId, frame in items:
			print "Thread ID: %d (reference count = %d)" % (
				threadId, sys.getrefcount(frame))
			print ''.join(traceback.format_list(traceback.extract_stack(frame)))
		items.sort()
		print "-" * 79
		sys.stdout.flush()
开发者ID:akkmzack,项目名称:RIOS-8.5,代码行数:20,代码来源:ThreadedAppServer.py


示例9: __call__

    def __call__(self):

        frames = threadframe.dict()
        this_thread_id = thread.get_ident()
        now = time.strftime("%Y-%m-%d %H:%M:%S")
        res = ["Threads traceback dump at %s\n" % now]
        for thread_id, frame in frames.iteritems():
            if thread_id == this_thread_id:
                continue

            # Find request in frame
            reqinfo = ''
            f = frame
            while f is not None:
                co = f.f_code

                if co.co_name == 'publish':
                    if co.co_filename.endswith('/publisher/publish.py') or \
                       co.co_filename.endswith('/ZPublisher/Publish.py'):
                        request = f.f_locals.get('request')
                        if request is not None:
                            reqinfo += (request.get('REQUEST_METHOD', '') + ' ' +
                                       request.get('PATH_INFO', ''))
                            qs = request.get('QUERY_STRING')
                            if qs:
                                reqinfo += '?'+qs
                        break
                f = f.f_back
            if reqinfo:
                reqinfo = " (%s)" % reqinfo

            output = StringIO()
            traceback.print_stack(frame, file=output)
            res.append("Thread %s%s:\n%s" %
                (thread_id, reqinfo, output.getvalue()))

        frames = None
        res.append("End of dump")
        return '\n'.join(res)
开发者ID:hoka,项目名称:plugins.zope.zthreads,代码行数:39,代码来源:browser.py


示例10: teardown_test_environment

def teardown_test_environment():
  """
  This method is called by nose_runner when
  the tests all finish.  This helps track
  down when tests aren't cleaning up after
  themselves and leaving threads hanging around.
  """
  import threading
  # We should shut down all relevant threads by test completion.
  threads = list(threading.enumerate())

  try:
    import threadframe
    import traceback
    if len(threads) > 1:
      for v in threadframe.dict().values():
        traceback.print_stack(v)
  finally:
    # threadframe is only available in the dev build.
    pass

  assert 1 == len(threads), threads

  django_mako.render_to_string = django_mako.render_to_string_normal
开发者ID:kthguru,项目名称:hue,代码行数:24,代码来源:tests.py


示例11: _threads

 def _threads():
   import threadframe
   return threadframe.dict().iteritems()
开发者ID:devinshields,项目名称:hue,代码行数:3,代码来源:views.py


示例12: dump_threads

import thread
import traceback
import time
from cStringIO import StringIO

try:
    # Available from Python >= 2.5
    from sys import _current_frames as threadframe
except ImportError:
    import threadframe as _threadframe
    # Wrapper to provide the same interface as the one from Python >= 2.5
    threadframe = lambda: _threadframe.dict()

import webob

def dump_threads():
    """Dump running threads

    Returns a string with the tracebacks.
    """

    frames = threadframe()
    this_thread_id = thread.get_ident()
    now = time.strftime("%Y-%m-%d %H:%M:%S")
    res = ["Threads traceback dump at %s\n" % now]
    for thread_id, frame in frames.iteritems():
        if thread_id == this_thread_id:
            continue

        # Find request in frame
        reqinfo = ''
开发者ID:sdouche,项目名称:repoze.debug,代码行数:31,代码来源:threads.py


示例13: U

print 'done'
print 'launching self-deadlocking thread...',
U().start()
print 'done'
print 'launching thread that will die before the end...',
v = V()
v.start()
print 'done'

time.sleep(5)

# Python 2.2 does not support threadframe.dict()
if sys.hexversion < 0x02030000:
  frames = threadframe.threadframe()
else:
  frames = threadframe.dict()

# signal the thread V to die, then wait for it to oblige
V_event.set()
v.join()

if sys.hexversion < 0x02030000:
  for frame in frames:
    print '-' * 72
    print 'frame ref count = %d' % sys.getrefcount(frame)
    traceback.print_stack(frame)
else:
  for thread_id, frame in frames.iteritems():
    print '-' * 72
    print '[%s] %d' % (thread_id, sys.getrefcount(frame))
    traceback.print_stack(frame)
开发者ID:2013Commons,项目名称:HUE-SHARK,代码行数:31,代码来源:test.py



注:本文中的threadframe.dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python threading._get_ident函数代码示例发布时间:2022-05-27
下一篇:
Python threades.resize_pt函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap