News for hackers. Stuff that matters.

lucaswiman

Re:Show HN: Python Concurrency Testing with Frontrun on Wednesday August 05, 2026 @10:34PM (#49191750)
A bit more about how it works internally. It uses sys.monitoring (or sys.set_trace for older versions of python), as well as LD_PRELOAD / DYNLIB libc patching to track arbitrary io events. It also monkeypatches basic concurrency primitives like the contents of `threading`. (Given how heavily monkeypatched that all is, I've been running frontrun tests separately from an ordinary test suite. The bundled binary handles all that when used with Pytest.)

It tracks "conflicts" at mutable boundaries, building: 1. A "shadow stack" recording when values are assigned to objects which are referenced from more than one thread. 2. A finer-grained model of SQL and Redis items that take into account some of the semantics of their concurrency models.

The code executes normally once, to get conflict points, then it uses a version of an algorithm called Dynamic Partial Order Reduction (DPOR) to efficiently search through all non-isomorphic traces looking for failures (either a crash, a statically detected deadlock, or a violation of the property/invariant provided in the test). This was partially inspired by the rust concurrency testing library Loom, though uses monkey-patching instead of customer concurrency primitives.

Show HN: Python Concurrency Testing with Frontrun

https://github.com/lucaswiman/frontrun

Hi HN, I'm the author of Frontrun, a Python concurrency testing library I built over the past 6 months using Claude Code and Codex. It uses bytecode tracing and various forms of monkeypatching to schedule across threads, async and multiprocessing allowing you to find and deterministically reproduce race conditions or deadlocks.It can understand Python variable assignments, SQL statements and...

( Read More... | 1 comment | on HN )
Re:Ask HN: Whose building on Python NoGIL? on Thursday January 02, 2025 @06:13PM (#42580087)
> I do get the impression that multi-threaded Python code is full of hazards that the GIL covers up.

It was a design goal of free-threading that any race condition which can occur in pure python code without the GIL must have already been possible on the same code with the GIL. To achieve that, they added various locks which fix cpython primitive operations that were only threadsafe because of the GIL. That's why single-threaded execution is slower without the GIL.

However, it's possible there were races which were very unlikely with the GIL that are much more likely now, e.g. one requiring multiple context switches in evaluating a single statement like `a.b = c[a.b].d()`. With the GIL, that might require multiple operations in that assignment taking >5ms. If all those operations are fast might almost never come up, but without the GIL, a different thread could mutate a.b as often as it wants.

I haven't heard of this coming up in practice, but it's certainly something that could in principle happen. The amount of FUD about it in every discussion about python finally making progress on threading seems excessive though.

Re:Ask HN: Who is hiring? (July 2021) on Thursday July 01, 2021 @06:53PM (#27705894)
Akasa (https://akasa.com) | ML, backend, golang/typescript/python | REMOTE (Must be located in the US) or onsite in SSF

Akasa is a healthcare automation company, pioneering "Unified Automation" that seamlessly integrates machine learning, human domain experts and traditional software automation into healthcare workflows for revenue cycle management and other areas. We combine deep domain knowledge of healthcare revenue cycle management with innovative technology. We have contracts with some of the largest healthcare providers in the US and are growing quickly.

We're currently hiring for several roles in machine learning, security/infrastructure and our automation platform. We're also hiring in implementation engineering positions that can provide a good career path to level up on software engineering. https://akasa.com/careers/

Re:Removing Python 2.x support from Django for version 2.0 on Thursday January 19, 2017 @03:06PM (#13439035)
I've upgraded a large (~700K LOC) Django project across several versions (1.5-1.9). I think Django does a reasonably good job of maintaining a good upgrade path, though they frequently break backwards compatibility, and at a pretty fast rate (now 8 months release cycles, which barely gives the community to catch up). Some of the changes like module renames seem pointless from an end user perspective, so it feels like the django core team shovels busywork onto users. I also find their method naming policies annoying, since they don't annotate "unsupported" features in any way (eg with an _attribute, and also some _attributes ARE supported). This makes it difficult to figure out whether you're "staying within the lines" of their support policy. I keep a checkout of the django repo around so I can grep the docs for mentions of a method before I use it.

That said, having started on updating that same codebase to Python 3, the Django team tries hard to provide the KEY thing you need to seamlessly update a codebase: a version which can support both incompatible features. Without this, you need to have one giant branch with a bunch of renames and other changes. They actually introduce deprecation warnings, and have something non-deprecated you can use in the same version. I think if Python core had introduced a version of Python including both versions of all the module renames with deprecation warnings, the community would be much further along on the upgrade path.

Re:Ask HN: What are some examples of beautiful software? on Monday March 14, 2016 @01:50AM (#11281282)
Peter Norvig's sudoku solver is beautiful on all levels. http://norvig.com/sudoku.html

It's clearly explained code that's shorter than you would have thought. Norvig showcases his expertise in manipulating both the basic data structure of the Python language, and a deep understanding of the underlying problem and methods for solving it.

Re:Learn Prolog Now on Wednesday March 25, 2015 @12:45AM (#9261339)
I definitely agree that the terminator is a good idea, just that "." happened to be an unfortunately historical choice since other languages used that character for a very different meaning.

Thanks for the links! These look extremely helpful!

Re:Learn Prolog Now on Wednesday March 25, 2015 @12:37AM (#9261316)
Right. I think this is how a lot of business requirements are specified, since they are frequently constructed by non-programmers. Taking a bunch of cases from a spec document generated by a domain expert and turning them into maintainable/readable procedural code takes a lot of creativity. I think it's easier to express case analysis like this in Prolog.
Re:Learn Prolog Now on Sunday March 22, 2015 @10:05PM (#9249122)
Datalog is a query language, but I haven't found good libraries for the "connector" pieces of translating prolog/datalog predicates to SQL, constructing or syncing schema definitions, and database migrations. It seems like if you want to use Datalog, Datomic is the best option. (But datomic is sort of pricey for commercial use relative to SQL databases like Postgresql.)
Re:Learn Prolog Now on Sunday March 22, 2015 @04:20PM (#9248066)
I've been actively trying to learn Prolog for the past few months. It's definitely very different from other languages I've used, and it's changed the way I think about programming. Prolog seems to be a really brilliant set of ideas embedded inside a mediocre syntax with poor library support for things that are trivially easy in other languages.

I think Prolog rules can replace a lot of spaghetti code: stuff like "Usually do this, but then other times do this, unless this other thing is true. If there's a parse error, then do xyz and keep going." In ordinary procedural code, the exception cases can dominate the body of a function and may need to be deeply nested, but in Prolog, it's possible to cordon them off or express them at the top level.

I suspect it might be most useful as a DSL you can embed inside of other languages, though I haven't seen a good implementation of that. (The clojure core.logic library mentioned elsewhere looks really promising.)

I think it may also be useful for domain experts to specify simple rules that capture an aspect of their expertise. If you restrict the domain down enough, and work to figure out what predicates are needed, prolog rules can become easy enough to read that you don't need to know much programming to use them. But the devil seems to be in the details of connecting the core logic into a bigger system that actually does something.

For example, the answer for hooking prolog up to a SQL database is "Look at the ODBC library!", which is not a very satisfactory answer. I think you could build a really beautiful ORM system in Prolog, but nobody's done it yet. (Maybe ORM isn't the right phrase, but a clean way of relating prolog queries to database queries and vice versa.)

The syntax is wonderfully simple, but also has almost no sugar for common idioms. The predicate notation makes it somewhat harder to batch up a bunch of attributes into one conceptual "thing" than in other languages. That means you need to keep positional arguments in your head a lot more. I think aping the class constructor and attribute notation of other languages would be helpful like `my_foo(foo, bar:attr, baz:attr) :- [...].` Then you could reference that either as a constructor (`my_foo(a,b,c)` would state that `a.bar=b` and `a.baz=c`) or to generate goals, like `my_foo(foo), other_predicate(foo.bar)`. Prolog is so old that choices like "make '.' the end of a statement" made sense at the time, but haven't stood the test of history.

(Disclaimer: Many of my criticisms may have perfectly valid solutions in prolog. I'm still learning it.)