You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.2KB

  1. # # # import timeit
  2. # # # class MyClass:
  3. # # # @staticmethod
  4. # # # def my_static_method():
  5. # # # pass
  6. # # # def my_function():
  7. # # # pass
  8. # # # # 通过类名调用静态方法
  9. # # # def test_static_method():
  10. # # # MyClass.my_static_method()
  11. # # # # 通过函数名调用函数方法
  12. # # # def test_function():
  13. # # # my_function()
  14. # # # # 测试执行速度
  15. # # # print("static method: ", timeit.timeit(test_static_method, number=10000000))
  16. # # # print("function: ", timeit.timeit(test_function, number=10000000))
  17. # # import copy
  18. # # import os
  19. # # import pickle
  20. # # import time
  21. # # import timeit
  22. # # import traceback
  23. # # from collections import namedtuple
  24. # # from concurrent.futures import ThreadPoolExecutor
  25. # # from multiprocessing import Queue
  26. # # from threading import Thread
  27. # #
  28. # # import cv2
  29. # # import psutil
  30. # #
  31. # # # def mu():
  32. # # # aa ={
  33. # # # 'half': 1,
  34. # # # 'iou_thres': (1,2,3),
  35. # # # 'allowedList': [1,3],
  36. # # # 'aa': {"1":"2"},
  37. # # # }
  38. # # # bb = aa.copy()
  39. # # # def mu1():
  40. # # # aa ={
  41. # # # 'half': 1,
  42. # # # 'iou_thres': (1,2,3),
  43. # # # 'allowedList': [1,3],
  44. # # # 'aa': {"1":"2"},
  45. # # # }
  46. # # # # copy.deepcopy(aa)
  47. # # # print(pickle.loads(pickle.dumps(aa)))
  48. # # # mu1()
  49. # # # print("static method1: ", timeit.timeit(mu, number=100000))
  50. # # # print("static method2: ", timeit.timeit(mu1, number=100000))
  51. # #
  52. # #
  53. # # # def aa():
  54. # # # Point = namedtuple('Point', ('x', 'y', 'z'))
  55. # # # aa = Point("1111111111", "22222222222", "333333333333")
  56. # # # aa.x
  57. # # # aa.y
  58. # # # aa.z
  59. # # # def aa1():
  60. # # # aa = ["1111111111", "22222222222", "333333333333"]
  61. # # # aa[0]
  62. # # # aa[1]
  63. # # # aa[2]
  64. # # # print("static method1: ", timeit.timeit(aa, number=100000))
  65. # # # print("static method2: ", timeit.timeit(aa1, number=100000))
  66. # # # aa=[]
  67. # # # aa[28] = "11111"
  68. # # # print(aa)
  69. # # # def aa1():
  70. # # # # 获取当前进程的父进程的PID
  71. # # # if psutil.pid_exists(psutil.Process(os.getpid()).ppid()):
  72. # # # print("11111")
  73. # # # else:
  74. # # # print("2222")
  75. # # # print("static method2: ", timeit.timeit(aa1, number=100))
  76. # # # def aa():
  77. # # # num=1
  78. # # # while num < 100:
  79. # # # num+=1
  80. # # # time.sleep(100)
  81. # # # dd = Thread(target=aa, args=())
  82. # # # dd.setDaemon(True)
  83. # # # dd.start()
  84. # # # try:
  85. # # # dd.join(1)
  86. # # # except Exception:
  87. # # # print(traceback.format_exc())
  88. # # # a = Queue()
  89. # # # aa = {"aa": "11"}
  90. # # # a.put(aa)
  91. # # # bb = a.get()
  92. # # # bb["aa"] = "2222"
  93. # # # print(aa)
  94. # # # print(bb)
  95. # #
  96. # #
  97. # # # def dd():
  98. # # # w = ["1111", "2222", "3333"]
  99. # # # a = w[2]
  100. # # #
  101. # # #
  102. # # # def cc():
  103. # # # aa = {"aa": "1111", "bb": "2222", "cc": "3333"}
  104. # # # t= aa["cc"]
  105. # # #
  106. # # # print("static method1: ", timeit.timeit(dd, number=1000))
  107. # # # print("static method2: ", timeit.timeit(cc, number=1000))
  108. # # import numpy as np
  109. # #
  110. # #
  111. # # # # 创建一个numpy数组
  112. # # # arr1 = np.array([[[1,2,3]], [[2,3, 4]]])
  113. # # # # 使用copy()方法深度拷贝数组
  114. # # # arr2 = arr1.copy()
  115. # # # # 修改arr2中的元素
  116. # # # arr2[0][0][1] = 5
  117. # # # # 打印arr1和arr2
  118. # # # print("arr1:", arr1)
  119. # # # print("arr2:", arr2)
  120. # # # def cop2():
  121. # # # arr1 = np.array([[1, 2], [3, 4]])
  122. # # # arr2 = arr1
  123. # # # def cop():
  124. # # # arr1 = np.array([[1, 2], [3, 4]])
  125. # # # arr2 = arr1.copy()
  126. # # # def cop1():
  127. # # # arr1 = np.array([[1, 2], [3, 4]])
  128. # # # arr2 = copy.deepcopy(arr1)
  129. # # # print("static method1: ", timeit.timeit(cop2, number=1000))
  130. # # # print("static method1: ", timeit.timeit(cop, number=1000))
  131. # # # print("static method2: ", timeit.timeit(cop1, number=1000))
  132. # #
  133. # # # aa = {}
  134. # # # def dd(aa):
  135. # # # aa["aa"] = 1
  136. # # #
  137. # # # dd(aa)
  138. # # # print(aa)
  139. # #
  140. # # def aa(num):
  141. # # while True:
  142. # # time.sleep(4)
  143. # # num+= 1
  144. # # raise Exception("1111")
  145. # #
  146. # #
  147. # # def dd():
  148. # # num = 1
  149. # # with ThreadPoolExecutor(max_workers=1) as t:
  150. # # ddd = t.submit(aa, num)
  151. # # while True:
  152. # # ddd.result()
  153. # # time.sleep(1)
  154. # # print(num)
  155. # #
  156. # # image = cv2.imread(r'D:\tuoheng\codenew\tuoheng_alg\image\logo.png')
  157. # # image1 = np.array(image)
  158. # # or_result, or_image = cv2.imencode(".jpg", image1)
  159. # # aa = or_image.tobytes()
  160. # #
  161. # # numpy_array = np.frombuffer(aa, dtype=np.uint8)
  162. # # img_bgr = cv2.cvtColor(numpy_array, cv2.COLOR_RGB2BGR)
  163. # # cv2.sh
  164. # # print(img_bgr)
  165. # import os
  166. # import time
  167. # from os import getpid
  168. #
  169. # import psutil
  170. #
  171. #
  172. # from multiprocessing import Process
  173. #
  174. # def fun2(name, pid):
  175. # while True:
  176. # time.sleep(1)
  177. # print("fun2", getpid(), os.getppid(), psutil.Process(getpid()).ppid(), psutil.pid_exists(psutil.Process(getpid()).ppid()))
  178. #
  179. # def fun1(name):
  180. # print('测试%s多进程' %name)
  181. # p = Process(target=fun2,args=('Python',getpid(),)) #实例化进程对象
  182. # # p.daemon = True
  183. # p.start()
  184. # print("funn1", getpid(), p.pid)
  185. #
  186. #
  187. #
  188. # if __name__ == '__main__':
  189. # p = Process(target=fun1,args=('Python',)) #实例化进程对象
  190. # # p.daemon = True
  191. # p.start()
  192. #
  193. #
  194. # print('结束测试', os.getpid())
  195. #
  196. listeningProcesses={"11111": "1111", "2222": "2222"}
  197. p = list(listeningProcesses.keys())
  198. p.reverse()
  199. print(p)