threading ---- python multi-threading Python 多线程

强制终止线程

https://blog.csdn.net/A18373279153/article/details/80050177?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import threading
import time
import inspect
import ctypes


def _async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""
    tid = ctypes.c_long(tid)
    if not inspect.isclass(exctype):
        exctype = type(exctype)
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
        raise SystemError("PyThreadState_SetAsyncExc failed")


def stop_thread(thread):
    _async_raise(thread.ident, SystemExit)


def test():
    while True:
        print('-------')
        # time.sleep(0.5)
        pass


if __name__ == "__main__":
    t = threading.Thread(target=test)
    t.start()
    time.sleep(5.2)
    print("main thread sleep finish")
    stop_thread(t)

pyinstaller ---- executable maker for python, Python 程序包装成可执行文件

Max Recursion Exceeded

  • 设置最大循环数
1
2
3
4
5
6
import sys
sys.setrecursionlimit(100000)

from PyInstaller.utils.hooks import collect_data_files, collect_submodules

block_cipher = None

收集动态导入模块 hidden modules

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
hiddenimports = collect_submodules('pkg_resources._vendor') + ['pkg_resources.py2_warn']

a = Analysis(['socketapi.py'],
         pathex=['d:\\Documents\\HSC_Chemistry\\python_side\\test_resconstruct'],
         binaries=[],
         datas=[('databases', 'databases')],
         hiddenimports=hiddenimports,   # **** ...... set hidden import s here
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=False)

aiohttp ---- Async IO Web Framework

Client

ClientSession

response

  • resp.status
一次性读取内容
  • resp.text()

    • 文本 str 类型
    • resp.text(encoding='gbk')
  • resp.read()

    • bytes 类型
  • resp.json()

    • 提取 json
流模式读取 Streaming Response Content
  • resp.content.read(10)

request

  • session.get
  • session.put
关键字参数 arguments
params
json
  • session.post(url, json={'test': 'value'})