Update asyncio/README.md
This commit is contained in:
@@ -1,15 +1,29 @@
|
|||||||
## nest_asyncio
|
## nest_asyncio
|
||||||
```python
|
```python
|
||||||
|
'Sync'
|
||||||
def Sync():
|
def Sync():
|
||||||
import asyncio, functools, importlib.util as I
|
import asyncio, functools, importlib.util as U
|
||||||
I.find_spec('nest_asyncio') or os.system('pip install -q nest_asyncio')
|
U.find_spec('nest_asyncio') or os.system('pip install -q nest_asyncio')
|
||||||
__import__('nest_asyncio').apply(); return lambda func: functools.wraps(
|
__import__('nest_asyncio').apply(); return lambda func: functools.wraps(
|
||||||
func)(lambda *args, **kwargs: asyncio.run(func(*args, **kwargs)))
|
func)(lambda *args, **kwargs: asyncio.run(func(*args, **kwargs)))
|
||||||
sync = Sync()
|
sync = Sync()
|
||||||
|
|
||||||
|
'playwright'
|
||||||
@sync
|
@sync
|
||||||
async def amain(): print('amain')
|
async def Page():
|
||||||
amain()
|
if not hasattr(Page, 'context'):
|
||||||
|
from playwright.async_api import async_playwright
|
||||||
|
playwright = await async_playwright().start()
|
||||||
|
browser = await playwright.firefox.launch(timeout=0)
|
||||||
|
Page.context = await browser.new_context()
|
||||||
|
page = await Page.context.new_page()
|
||||||
|
for attr in dir(page):
|
||||||
|
if callable(method := getattr(page, attr)) and not attr.startswith('_'):
|
||||||
|
setattr(page, attr, sync(method))
|
||||||
|
return page
|
||||||
|
page = Page()
|
||||||
|
page.goto('http://example.com')
|
||||||
|
print(page.title()) # Example Domain
|
||||||
```
|
```
|
||||||
|
|
||||||
## threading
|
## threading
|
||||||
|
|||||||
Reference in New Issue
Block a user