rgfergrg
This commit is contained in:
57
test111.py
57
test111.py
@@ -1,26 +1,43 @@
|
||||
import threading
|
||||
import random
|
||||
import time
|
||||
|
||||
def daemon_thread_function():
|
||||
print("守护线程开始")
|
||||
time.sleep(5)
|
||||
print("守护线程结束")
|
||||
import requests
|
||||
from tonutils.utils import to_amount
|
||||
|
||||
def non_daemon_thread_function():
|
||||
print("非守护线程开始")
|
||||
time.sleep(2)
|
||||
print("非守护线程结束")
|
||||
|
||||
# 创建守护线程
|
||||
daemon_thread = threading.Thread(target=daemon_thread_function, daemon=True)
|
||||
# 创建非守护线程
|
||||
non_daemon_thread = threading.Thread(target=non_daemon_thread_function)
|
||||
def get_ton_num(address):
|
||||
headers = {
|
||||
'accept': '*/*',
|
||||
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||
'authorization': 'Bearer AFPJTKEBPOX3AIYAAAAKA2HWOTRNJP5MUCV5DMDCZAAOCPSAYEYS3CILNQVLF2HWKED6USY',
|
||||
'cache-control': 'no-cache',
|
||||
'content-type': 'application/json',
|
||||
'dnt': '1',
|
||||
'origin': 'https://tonviewer.com',
|
||||
'pragma': 'no-cache',
|
||||
'priority': 'u=1, i',
|
||||
'referer': 'https://tonviewer.com/',
|
||||
'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'cross-site',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0',
|
||||
}
|
||||
|
||||
# 启动线程
|
||||
daemon_thread.start()
|
||||
non_daemon_thread.start()
|
||||
for i in range(3):
|
||||
try:
|
||||
response = requests.get(
|
||||
f'https://tonapi.io/v2/accounts/{address}',
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
print("主线程继续执行")
|
||||
# 主线程等待非守护线程结束
|
||||
non_daemon_thread.join()
|
||||
print("主线程结束")
|
||||
return to_amount(int(response.json()["balance"]))
|
||||
except:
|
||||
time.sleep(random.random())
|
||||
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(get_ton_num(address="EQD-8WpOhknZ6Wip9EN-jz5Tw-SJvYgu_x2FSDFlXH1kSo2O"))
|
||||
Reference in New Issue
Block a user