PyCon TW 2023

The snake of Theseus 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 - 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 by Peacock (Yoichi Takai)

Slide: https://slides.p3ac0ck.net/pycontw2023/index.html

  • PEPs: 517, 621, and 660
  • 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

Asyncio Evolved: Enhanced Exception Handling with Python 3.11 TaskGroups by Junya Fukuda

asyncio.TaskGroup is a new feature since Python 3.11.

Example:

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.

SimpleArray between Python and C++ 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 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, which implements a kind of proof by exhaustion for test cases' inputs.

Examples:

import ipaddress

from hypothesis import given, strategies as st

@given(st.ip_addresses())
    def test_specifc(ip):
    ipaddress.ip_address(ip)
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 的冒險旅程 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 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(

xn+1) = f(
xn
) +
An
, then
An
= f(
xn+1
) - f(
xn
) =>
An
has no relationship with
An1

Automating Victory: Beating browser games with accessible Python by Jon Gaul

  • MSS: An ultra fast cross-platform multiple screenshots module in pure python using ctypes.
  • 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 by Yuichiro Tachibana

Slide: https://slides.com/whitphx/streamlit-meets-webassembly-stlite

Streamlit: Sever - client

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

stlite: Client-side execution only

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • Web assembly runs CPython -> runs Pyodide 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