摘要:
方法1:采用sys.exit(0)正常终止程序,从图中可以看到,程序终止后shell运行不受影响。 方法2:采用os._exit(0)关闭整个shell,从图中看到,调用sys._exit(0)后整个shell都重启了(RESTART Shell)。 方法3:采用Ctrl+C快捷键,强制终止程序执行 阅读全文
摘要:
``` 用asyncio和aiohttp抓取博客的总阅读量 (提示:先用接又找到每篇文章的链接) https://www.jianshu.com/u/130f76596b02 import re import asyncio import aiohttp import requests import 阅读全文
摘要:
``` coding:utf 8 import re import ssl import csv import json import time import random import asyncio import aiohttp import requests from lxml import 阅读全文
摘要:
``` coding:utf 8 import asyncio 通过create_task()方法 async def a(t): print(' ', t) await asyncio.sleep(0.5) print(' 阅读全文
摘要:
``` coding:utf 8 通过gather方法 import asyncio async def a(t): print(' ', t) await asyncio.sleep(0.5) print(' 阅读全文
摘要:
```
import aiohttp
import asyncio
import ssl async def fetch(session, url): async with session.get(url,ssl=ssl.SSLContext()) as response: return await response.text() async def main(): ... 阅读全文
摘要:
```
# 多线程
import threading
import time class myThread(threading.Thread): def __init__(self, threadID, name, counter): threading.Thread.__init__(self) self.threadID = threadID ... 阅读全文
摘要:
```
# 多进程,使用Process对象
from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p_1 = Process(target=f, args=('bob',)) p_1.start() p_1.join() ... 阅读全文
摘要:
```
# 多进程,使用Pool
from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': p = Pool(5) list = [1,2,3,4,5,6,7,8,9] print(p.map(f, list))
``` ```
# 多进程,使用Pool
i... 阅读全文
摘要:
``` # 模拟登录微博 import time import base64 import rsa import binascii import requests import re import random try: from PIL import Image except BaseException: pass try: from urllib.parse impo... 阅读全文