# PyCon TW 2023 ## [The snake of Theseus](https://tw.pycon.org/2023/en-us/conference/keynotes#Pablo%C2%A0Galindo%C2%A0Salgado) by Pablo Galindo Salgado **NoGIL** is most impressive! * Fomal discussion starts from OCT.7 2021 * NOGIL Python targeting 3.11 * JAN 9 2023 * [PEP 703](https://peps.python.org/pep-0703/) - tentatively accepted for Python 3.13 ### Challenges of NoGIL 1. maintanance: increase the Python team’s maintenance bourden 2. compatibility: issues for C extensions 3. performance: NoGIL Python may be imcompatible with servral faster Python optimisations 4. packaging: for a while packages might need to be released in two versions (as GIL and NoGIL), which complicates releases and testing, too ### Types of programs * I/O bounded code: doesn’t quite benefit from NoGIL * CPU bounded code: does benefit from NoGIL if there’s parallelism mixed workload ### Challengs for c extensions * global state * debugging is harder * implicit gil as lock * interoperabitpality * looking infrastructure * validation ## [Comparison of Packaging Tools in 2023](https://tw.pycon.org/2023/en-us/conference/talk/274) by Peacock (Yoichi Takai) Slide: https://slides.p3ac0ck.net/pycontw2023/index.html * PEPs: [517](https://peps.python.org/pep-0517/), [621](https://peps.python.org/pep-0621/), and [660](https://peps.python.org/pep-0660/) * `pyproject.toml` format was defined pyproject.toml https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/ Note: [Pipfile: the replacement for requirements.txt](https://github.com/pypa/pipfile/blob/main/README.rst) ## [Asyncio Evolved: Enhanced Exception Handling with Python 3.11 TaskGroups](https://tw.pycon.org/2023/en-us/conference/talk/280) by Junya Fukuda [`asyncio.TaskGroup`](https://docs.python.org/3/library/asyncio-task.html#asyncio.TaskGroup) is a new feature since Python 3.11. Example: ```python async def main(): async with asyncio.TaskGroup() as tg: task1 = tg.create_task(some_coro(...)) task2 = tg.create_task(another_coro(...)) print("Both tasks have completed now.") ``` The `async with` statement will wait for all tasks in the group to finish. While waiting, new tasks may still be added to the group (for example, by passing tg into one of the coroutines and calling `tg.create_task()` in that coroutine). Once the last task has finished and the `async with` block is exited, no new tasks may be added to the group. * In the past, uses [`asyncio.gather`](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather). ## [SimpleArray between Python and C++](https://tw.pycon.org/2023/en-us/conference/talk/300) by Yung-Yu Chen Slide: https://www.slideshare.net/YungYuChen/simplearray-between-python-and-cpdf Goal: Speed up computation! * Key: Buffer Management * SimpleArray is a class template * Holds a contiguous memory buffer * Provides multi-dimensional accessors to its elements ## [Property-Based Testing in Python](https://tw.pycon.org/2023/en-us/conference/talk/294) by Rain Wu Slide: https://drive.google.com/file/d/1cejbP-QVDtUphQ292FOB1RgyonDVmcYP/view?usp=sharing I think this is more like a coverage issue. Introduce [Hypothesis](https://hypothesis.readthedocs.io/en/latest/), which implements a kind of proof by exhaustion for test cases' inputs. Examples: ```python import ipaddress from hypothesis import given, strategies as st @given(st.ip_addresses()) def test_specifc(ip): ipaddress.ip_address(ip) ``` ```python from hypothesis import given, strategies as st class Speaker: def __init__(self, name: str, intro: str) -> None: self.name = name self.intro = intro @st.composite def speakers(draw): return Speaker( draw(st.text(printable, min_size=1, max_size=10)), draw(st.text(printable, min_size=1, max_size=150)), ) @given(speakers()) def test_composite(speaker: Speaker): assert 0 < len(speaker.name) <= 10 assert 0 < len(speaker.intro) <= 150 ``` Note: It lists as more inputs / property values for test cases as possible. However, that makes tests take more execution time, too. ## [從啟程到回歸都是 Python 的冒險旅程](https://tw.pycon.org/2023/en-us/conference/keynotes#Yen-lung_Tsai) by Yen-lung Tsai Slide: https://drive.google.com/file/d/1BEZzb6NDBXYwu4_pYDHFmk6sEnEHT2UC/view Professor Tsai introduced Generative AI in general science way. ### Text example: * Input one word (memory (in brain)), guess next word * The possible next words are **probability distribution** * Calcualte **probability distribution** according to the before gathered data/sentence/words ### Picture example: * Neural network can calculate/extract the characteristics of a person's picture. => Get the **representing vector** of the person's picture. * Check two pictures by comparing the distance between the vectors from two pictures. ## [當AI遇上財經-利用Graph Neural Network分析財經市場 When AI Meets Finance: Using Graph Neural Network to Analyze Financial Market](https://tw.pycon.org/2023/en-us/conference/talk/293) by William Chang Slide: https://docs.google.com/presentation/d/1OK_G9lLmiYelaii3hq35xomRYOiVGJW_SZNuI6DuRx4/edit#slide=id.g267e08f8fe1_0_366 Another AI thing, and used to guess stocks' price. If f($x_{n+1}$) = f($x_n$) + $A_n$, then $A_n$ = f($x_{n+1}$) - f($x_n$) => $A_n$ has no relationship with $A_{n-1}$ ## [Automating Victory: Beating browser games with accessible Python](https://tw.pycon.org/2023/en-us/conference/talk/295) by Jon Gaul * [MSS](https://python-mss.readthedocs.io/): An ultra fast cross-platform multiple screenshots module in pure python using ctypes. * [PyAutoGUI](https://pypi.org/project/PyAutoGUI/): A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard. May be they are good tools to do the automation GUI tests. ## [Streamlit meets WebAssembly - stlite](https://tw.pycon.org/2023/en-us/conference/talk/301) by Yuichiro Tachibana Slide: https://slides.com/whitphx/streamlit-meets-webassembly-stlite ### [Streamlit](https://streamlit.io/): Sever - client ![](https://hackmd.io/_uploads/H1ZipD2A3.png) ### [stlite](https://github.com/whitphx/stlite): Client-side execution only ![](https://hackmd.io/_uploads/SyySAwn03.png) * Web assembly runs CPython -> runs [Pyodide](https://pyodide.org/en/stable/) runtime -> Streamlit runs Python script as the ** web server** on the web browser * Normal JS runtime as the **web client** * No extra asyncio's event loops. In the browser/Node environment, the async features rely on the JS runtime. **There is only single running event loop.** * Does not have some blocking methods, like `time.sleep()`, but `await asyncio.sleep()` * Unavailable Python packages supports: check [Packages built in Pyodide](https://pyodide.org/en/stable/usage/packages-in-pyodide.html)