区块链技术博客
www.b2bchain.cn

Python:PyCharm在运行模式与调试模式下的不同行为 – python程序员分享

本文介绍了Python:PyCharm在运行模式与调试模式下的不同行为 – python程序员分享,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

在没有附加调试器的情况下从PyCharm运行时,Python代码的行为与在附加pydev时运行时的行为有所不同。

我在PyCharm中运行POX SDN控制器,并在控制台中运行Mininet模拟,该模拟连接了POX打开的侦听套接字。在调试模式下运行时,一旦Mininet模拟连接到POX进程且不会产生任何错误,POX进程就会立即完成,而在运行模式下它将继续按预期运行。这是输出:

跑:

/usr/bin/python2.7 /home/wirate/pyretic/pyretic.py pyretic.sdx.main Initialize SDX SDX: {'_policy': drop, 'notify': None, 'arp_policy': [DynamicPolicy] packets FwdBucket} Creating SDX environment from the config files Adding Physical ports for  A Adding virtual ports for  A Adding Physical ports for  C Adding virtual ports for  C Adding Physical ports for  B Adding virtual ports for  B {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'C': [3, 4]}, u'B': {u'B': [2]}} {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'A': [1], u'C': [3, 4], u'B': [2]}, u'B': {u'B': [2]}} {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'A': [1], u'C': [3, 4], u'B': [2]}, u'B': {u'A': [1], u'C': [3], u'B': [2]}} Parsing participant's policies Starting VNH Assignment After new assignment Virtual Next Hop --> IP Prefix:  {'VNH1': set([u'110.0.0.0/24', u'100.0.0.0/24']), 'VNH2': set([u'140.0.0.0/24', u'150.0.0.0/24'])} Virtual Next Hop --> Next Hop IP Address (Virtual):  {'VNH1': '172.0.1.1', 'VNH2': '172.0.1.2', 'VNH': [IPAddress('172.0.1.0'), IPAddress('172.0.1.1'), IPAddress('172.0.1.2'), IPAddress('172.0.1.3'), IPAddress('172.0.1.4'), IPAddress('172.0.1.5'), IPAddress('172.0.1.6'), IPAddress('172.0.1.7'), IPAddress('172.0.1.8'), IPAddress('172.0.1.9'), IPAddress('172.0.1.10'), IPAddress('172.0.1.11'), IPAddress('172.0.1.12'), IPAddress('172.0.1.13'), IPAddress('172.0.1.14'), IPAddress('172.0.1.15')]} Virtual Next Hop --> Next Hop Mac Address (Virtual) {'VNH1': aa:00:00:00:00:01, 'VNH2': aa:00:00:00:00:02, 'VNH': 'aa:00:00:00:00:00'} Completed VNH Assignment POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. Connected to pyretic frontend. DEBUG:core:POX 0.2.0 (carp) going up... DEBUG:core:Running on CPython (2.7.8/Oct 20 2014 15:05:19) DEBUG:core:Platform is Linux-3.16.0-24-generic-x86_64-with-Ubuntu-14.10-utopic INFO:core:POX 0.2.0 (carp) is up. DEBUG:openflow.of_01:Listening on 0.0.0.0:6633 INFO:openflow.of_01:[00-00-00-00-00-01 1] connected 

调试:

/usr/bin/python2.7 /home/wirate/pycharm-4.0/helpers/pydev/pydevd.py --multiproc --client 127.0.0.1 --port 49196 --file /home/wirate/pyretic/pyretic.py pyretic.sdx.main pydev debugger: process 5555 is connecting  Connected to pydev debugger (build 139.574) Initialize SDX SDX: {'_policy': drop, 'notify': None, 'arp_policy': [DynamicPolicy] packets FwdBucket} Creating SDX environment from the config files Adding Physical ports for  A Adding virtual ports for  A Adding Physical ports for  C Adding virtual ports for  C Adding Physical ports for  B Adding virtual ports for  B {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'C': [3, 4]}, u'B': {u'B': [2]}} {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'A': [1], u'C': [3, 4], u'B': [2]}, u'B': {u'B': [2]}} {u'A': {u'A': [1], u'C': [3], u'B': [2]}, u'C': {u'A': [1], u'C': [3, 4], u'B': [2]}, u'B': {u'A': [1], u'C': [3], u'B': [2]}} Parsing participant's policies Starting VNH Assignment After new assignment Virtual Next Hop --> IP Prefix:  {'VNH1': set([u'110.0.0.0/24', u'100.0.0.0/24']), 'VNH2': set([u'140.0.0.0/24', u'150.0.0.0/24'])} Virtual Next Hop --> Next Hop IP Address (Virtual):  {'VNH1': '172.0.1.1', 'VNH2': '172.0.1.2', 'VNH': [IPAddress('172.0.1.0'), IPAddress('172.0.1.1'), IPAddress('172.0.1.2'), IPAddress('172.0.1.3'), IPAddress('172.0.1.4'), IPAddress('172.0.1.5'), IPAddress('172.0.1.6'), IPAddress('172.0.1.7'), IPAddress('172.0.1.8'), IPAddress('172.0.1.9'), IPAddress('172.0.1.10'), IPAddress('172.0.1.11'), IPAddress('172.0.1.12'), IPAddress('172.0.1.13'), IPAddress('172.0.1.14'), IPAddress('172.0.1.15')]} Virtual Next Hop --> Next Hop Mac Address (Virtual) {'VNH1': aa:00:00:00:00:01, 'VNH2': aa:00:00:00:00:02, 'VNH': 'aa:00:00:00:00:00'} Completed VNH Assignment pydev debugger: process 5595 is connecting  POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. Connected to pyretic frontend. DEBUG:core:POX 0.2.0 (carp) going up... DEBUG:core:Running on CPython (2.7.8/Oct 20 2014 15:05:19) DEBUG:core:Platform is Linux-3.16.0-24-generic-x86_64-with-Ubuntu-14.10-utopic INFO:core:POX 0.2.0 (carp) is up. DEBUG:openflow.of_01:Listening on 0.0.0.0:6633 INFO:openflow.of_01:[None 1] closed INFO:openflow.of_01:[00-00-00-00-00-01 2] connected  Process finished with exit code 137 

这是启动控制器的代码:

def main():     global of_client     (op, options, args, kwargs_to_pass) = parseArgs()     if options.mode == 'i':         options.mode = 'interpreted'     elif options.mode == 'r0':         options.mode = 'reactive0'     elif options.mode == 'p0':         options.mode = 'proactive0'     elif options.mode == 'p1':         options.mode = 'proactive1'     try:         module_name = args[0]     except IndexError:         print 'Module must be specified'         print ''         op.print_usage()         sys.exit(1)     try:         module = import_module(module_name)     except ImportError, e:         print 'Must be a valid python module'         print 'e.g, full module name,'         print '     no .py suffix,'         print '     located on the system PYTHONPATH'         print ''         print 'Exception message for ImportError was:'         print e         sys.exit(1)      main = module.main     kwargs = { k : v for [k,v] in [ i.lstrip('--').split('=') for i in kwargs_to_pass ]}      sys.setrecursionlimit(1500) #INCREASE THIS IF "maximum recursion depth exceeded"      # Set up multiprocess logging.     verbosity_map = { 'low' : logging.WARNING,                       'normal' : logging.INFO,                       'high' : logging.DEBUG,                       'please-make-it-stop' : logging.DEBUG }     logging_queue = Queue()      # Make a logging process.     def log_writer(queue, log_level):         formatter = logging.Formatter('%(levelname)s:%(name)s: %(message)s')         handler = logging.StreamHandler()         handler.setFormatter(formatter)         handler.setLevel(log_level)         logger = logging.getLogger()         logger.addHandler(handler)         logger.setLevel(log_level)         while(True):             try:                 to_log = queue.get()             except KeyboardInterrupt, e:                 print "nkilling log"                 import sys                 sys.exit(0)             logger.handle(to_log)     log_level = verbosity_map.get(options.verbosity, logging.DEBUG)     log_process = Process(target=log_writer,args=(logging_queue, log_level,))     log_process.daemon = True     log_process.start()      # Set default handler.     logger = logging.getLogger()     handler = util.QueueStreamHandler(logging_queue)     logger.addHandler(handler)     logger.setLevel(log_level)      runtime = Runtime(Backend(),main,kwargs,options.mode,options.verbosity)     if not options.frontend_only:         try:             output = subprocess.check_output('echo $PYTHONPATH',shell=True).strip()         except:             print 'Error: Unable to obtain PYTHONPATH'             sys.exit(1)         poxpath = None         for p in output.split(':'):              if re.match('.*pox/?$',p):                  poxpath = os.path.abspath(p)                  break         if poxpath is None:             print 'Error: pox not found in PYTHONPATH'             sys.exit(1)         pox_exec = os.path.join(poxpath,'pox.py')         python=sys.executable         # TODO(josh): pipe pox_client stdout to subprocess.PIPE or         # other log file descriptor if necessary         of_client = subprocess.Popen([python,                                        pox_exec,                                       '--verbose',                                       'of_client.pox_client' ],                                      stdout=sys.stdout,                                      stderr=subprocess.STDOUT)      signal.signal(signal.SIGINT, signal_handler)     signal.pause() 

也许我应该补充一点,我以root用户身份运行PyCharm,因为启动控制器需要特权。

参考方案

我的项目在Debug中工作,而在Run中失败。在修订过程中,这几次发生在我身上。
尝试的解决方案包括:

重新启动PyCharm
更新中
更新到新的PyCharm安装
清除缓存
仅使用python文件开始一个新项目
等等

一件事为我解决了这个问题。

我转到“运行”菜单->“附加到本地进程..”
我选择了唯一可用的选项“ pydevconsole.py”(名称后面还有一些进程ID)。

问题解决了;它在运行和调试中均有效。

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)… python文件:def get(request): … return Response(seriali…

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

烧瓶学习问题为了定制对匿名用户的要求,我在模型中设置了一个类: class MyAnonymousUser(AnonymousUserMixin): def can(self, permissions): return False def is_administrator(self): return False login_manager.anonymous…

我正在使用本地节点js脚本来处理字符串。我陷入了将’-‘字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Python:PyCharm在运行模式与调试模式下的不同行为 – python程序员分享
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们