algN/vodsdk/test/线程/Test.py

61 lines
1.4 KiB
Python
Raw Normal View History

2025-08-23 10:12:26 +08:00
# -*- coding: utf-8 -*-
import threading
import time
from concurrent.futures import ThreadPoolExecutor, ALL_COMPLETED, wait
class Test(object):
def __init__(self):
# threading.Thread.__init__(self)
self._sName = "machao"
def process(self):
#args是关键字参数需要加上名字写成args=(self,)
th1 = threading.Thread(target=self.buildList, args=())
th1.start()
th1.join()
def buildList(self):
while True:
print("start")
print(self._sName)
self._sName = "1111111"
time.sleep(3)
def bb():
print("!1111111111")
def aa(aa):
print(aa)
time.sleep(5)
return "1111"
# test = Test()
# test.process()
# print(3//2)
# with ThreadPoolExecutor(max_workers=10) as t:
# aa = t.submit(aa, "aaa")
# results = wait([aa], timeout=60, return_when=ALL_COMPLETED)
# completed_futures = results.done
# for f in completed_futures:
# if f.exception():
# raise f.exception()
# else:
# print(f"Task {f.result()} succeeded")
def test1(message):
while True:
time.sleep(1)
print(message)
message = {"a": "1", "b": "2", "c": "3"}
aa = message
print(aa is message)
message = None
print(aa)
print(message)
# with ThreadPoolExecutor(max_workers=10) as t:
# t.submit(test1, message)
# print("1111111111111111111111111111111")
# del message
# print("aaa", message)