From bf2891815b0c65347f6131d597fe5e86101889b3 Mon Sep 17 00:00:00 2001 From: JJJZXY <1522844911@qq.com> Date: Thu, 14 Jan 2021 12:33:50 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E4=BA=94?= =?UTF-8?q?=E5=91=A8=E4=BD=9C=E4=B8=9A=2001.011-01.17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/.keep" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From 441ba45695bb3194fa54aeecb707134334c7bb36 Mon Sep 17 00:00:00 2001 From: JJJZXY <1522844911@qq.com> Date: Thu, 14 Jan 2021 12:34:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\254\344\270\200\350\212\202/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/.keep" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From d2a29937293baa7c89ebca58cef945e6214c6b87 Mon Sep 17 00:00:00 2001 From: JJJZXY <1522844911@qq.com> Date: Thu, 14 Jan 2021 12:34:43 +0800 Subject: [PATCH 3/5] =?UTF-8?q?add=20=E7=AC=AC=E4=BA=8C=E6=9C=9F=E8=AE=AD?= =?UTF-8?q?=E7=BB=83=E8=90=A5/5=E7=8F=AD/5=E7=8F=AD=5F=E5=BC=A0=E5=85=B4?= =?UTF-8?q?=E9=9B=A8/=E7=AC=AC=E4=BA=94=E5=91=A8=E4=BD=9C=E4=B8=9A=2001.01?= =?UTF-8?q?1-01.17/=E7=AC=AC=E4=B8=80=E8=8A=82/=E7=AC=AC=E4=B8=80=E8=8A=82?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\254\344\270\200\350\212\202" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\347\254\254\344\270\200\350\212\202" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\347\254\254\344\270\200\350\212\202" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\347\254\254\344\270\200\350\212\202" new file mode 100644 index 00000000..f4d9dd73 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\270\200\350\212\202/\347\254\254\344\270\200\350\212\202" @@ -0,0 +1,24 @@ +# 实现一个多线程程序 +import requests +import requests +from threading import Thread +from multiprocessing import Process +def request_bilibili(): + url = "https://www.bilibili.com/v/douga/?spm_id_from=333.851.b_7072696d6172794368616e6e656c4d656e75.1" + body = "" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" + } + response = requests.get(url=url, headers=headers) + print(response) + +if __name__ == "__main__": + for i in range(10): + t = Thread(target=request_bilibili) + t.start() + +#转换为多进程 +if __name__ == "__main__": + for i in range(10): + p = Process(target=request_bilibili) + p.start() -- Gitee From 78633c637427f9c76aec47db31dc6d3f2391c9ca Mon Sep 17 00:00:00 2001 From: JJJZXY <1522844911@qq.com> Date: Sat, 16 Jan 2021 09:38:42 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\254\344\272\214\350\212\202/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/.keep" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From d65c1d6e6445b96bdb7d65332eb042ab36b065fa Mon Sep 17 00:00:00 2001 From: JJJZXY <1522844911@qq.com> Date: Sat, 16 Jan 2021 09:39:37 +0800 Subject: [PATCH 5/5] =?UTF-8?q?add=20=E7=AC=AC=E4=BA=8C=E6=9C=9F=E8=AE=AD?= =?UTF-8?q?=E7=BB=83=E8=90=A5/5=E7=8F=AD/5=E7=8F=AD=5F=E5=BC=A0=E5=85=B4?= =?UTF-8?q?=E9=9B=A8/=E7=AC=AC=E4=BA=94=E5=91=A8=E4=BD=9C=E4=B8=9A=2001.01?= =?UTF-8?q?1-01.17/=E7=AC=AC=E4=BA=8C=E8=8A=82/=E4=BD=9C=E4=B8=9A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\344\275\234\344\270\232" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\344\275\234\344\270\232" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\344\275\234\344\270\232" new file mode 100644 index 00000000..7392bd50 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\344\272\224\345\221\250\344\275\234\344\270\232 01.011-01.17/\347\254\254\344\272\214\350\212\202/\344\275\234\344\270\232" @@ -0,0 +1,61 @@ +from threading import Thread, Lock +from multiprocessing import Process, Lock +from multiprocessing import Queue, Array, Value + + +#多进程锁 + +def save_to_pfile(index, lock): + with lock: + with open("ex2.log", "a", encoding="utf-8") as f: + f.write(str(index) + "\n") + +if __name__ =="__main__": + process_array=[] + lock = Lock() + for i in range(10): + p = Process(target=save_to_pfile, args=(i, lock)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + print("done!") + +# 多线程锁 + +zero = 0 +lock = Lock() +def save_to_tfile(): + global zero + for i in range(10**7): + zero += 1 + zero -= 1 + +if __name__ == "__main__": + thread_array = [] + for i in range(10): + t = Thread(target=save_to_tfile) + thread_array.append(t) + t.start() + for t in thread_array: + t.join() + print("done!") + print(zero) + +# 消息队列 +def save_to_queue(index, my_queue): + my_queue.put(index) + +if __name__ == "__main__": + process_array = [] + my_queue = Queue() + for i in range(10): + p = Process(target=save_to_queue, args=(i, my_queue)) + process_array.append(p) + p.start() + for p in process_array: + p.join() + + while True: + print(my_queue.get()) + -- Gitee