News for hackers. Stuff that matters.
Re:Please, stop pushing for static typing in Python by geofft on Tuesday February 01, 2022 @05:29PM (#30170451)
Asyncio is weird. But check out Trio, an alternative and easier-to-understand async framework: https://trio.readthedocs.io/en/stable/tutorial.html

Trio solves a problem that threading does not: switching between tasks only happens at deterministic points (they don't run in parallel), and tasks are in a hierarchy so that exceptions are handled in reasonable ways (and you can do a lot of other associated cool things like cancel an entire tree of tasks).

Python has a GIL, so you're not getting parallel Python code anyway without multiprocessing.

This means that if I'm writing code that implements, like, a basic network server, by far the easiest way to do it is Trio. Unlike with threading (in Python or any other language) I don't have to worry about locks from concurrent access / tasks switching at unexpected points, and unlike with e.g. the select module, handling both directions of communication and multiple connections is doable with normal straight-line code instead of weird state machines.

It's not needed, yes, but neither is Python itself. You could just write C.

Re:Please, stop pushing for static typing in Python by akagusu on Wednesday February 02, 2022 @11:37AM (#30179901)
I love Trio, much better than the standard asyncio.

> It's not needed, yes, but neither is Python itself. You could just write C.

I'm currently learning C, so I can use Python as a front-end for C, giving users a nice interface while using C to handle the hard work, which is what lots of Python libraries do under the hood.

If C is not your thing, there are some interesting projects to use other languages with Python [https://github.com/PyO3/PyO3] | [https://github.com/yglukhov/nimpy]

Re:Please, stop pushing for static typing in Python by wheelerof4te on Wednesday February 02, 2022 @01:11PM (#30181463)
Python and C work wonders together.

I must admit that writing in C gives a more fun challenge.