1. Debug (PDB)
Code:
[[email protected] Gaoji]# vim test2.py 1 # !/usr/local/bin/python3 2 # -*-coding:utf-8-*- 3 4 def Getaverage (A, B): 5 result = a + b 6 print (" result=%d " %result) 7 return result 8 9 A = ten B = 2 XX C = a + b ret = Getaverage (A, b) print (ret)
[[email protected] Gaoji]#python3-m pdb test2.py>/home/weixin/gaoji/test2.py (4) <module>()-defGetaverage (A, b):(Pdb) L1#!/usr/local/bin/python32#-*-coding:utf-8-*-3 4defGetaverage (A, b):5 result = a +b6Print("result=%d"%result)7returnresult8 9 A = ten B = a + c = a +B (Pdb)
############################### #进程 ########################
Multi-tasking understanding:
######### #父进程与子进程的先后顺序理解 ################
[[email protected] process]#Vim 01-process. PY1#!/usr/local/bin/python32#-*-coding:utf-8-*-3 4ImportOS5Import Time6 ret =os.fork ()7 8ifRET = =0:9Print('---child process 1---') Ten Time.sleep (5) 11Print('---child process 2---') 12Else: 13Print('---parent process---') Time.sleep (3) 15 16Print('---over---')
Execution Result:
Summary: The value of RET has two, one is equal to 0, one is greater than 0; White point is executed two times.
################ #全局变量在多进程中不共享 ##############
[[email protected] process]#Vim 02-process. PY1#!/usr/local/bin/python32#-*-coding:utf-8-*-3 4 5ImportOs-6Import Time7 G_sum = 8 9 pid =os.fork ()10ifPID = =0:11Print('---process-01---') G_sum + = 1 13Print('---process-01--%d'%g_sum)14Else: Time.sleep (3) # # #为了保证让子进程优先运行16Print('---process-02---') 17Print('---process-02--%d'%g_sum)18
Execution Result:
[[email protected] process] # ---process-01------process-01--101---process-02------process-02--100 # # #结果还是100, and did not become 101
Python's system programming--process