[Python-Dev] custom thread scheduler to test user synchronisation code

Dima Tisnek dimaqq at gmail.com
Thu Nov 21 11:53:09 CET 2013


First, in case such project already exists, could someone point me towards this?

It occurs to me that in some cases may be possible to run exhaustive
test on user-implemented synchronisation code.

let's say, in a simple case, we've got a 2 threads, some user code
using threading.* primitives to synchronise these threads and a unit
test that ensures the logical result of synchronisation is sane.

now, cpython relies on OS to schedule these 2 threads, however, if
this scheduler was under my control, I could force this test case into
many different, distinct thread interleaves. Granted, the total number
of interleaves is exponential and even unbounded in presence of loops.
Yet for small user code and unit test, this could even be exhaustive.

In a brute-force case, a new interleave should be branched off after
every bytecode evaluation (and in case of extensions GIL
acquisition/release). A smarter tester could possibly track primitive
and data accesses by threads and only create interleave branch when
there's potential of something being used by both threads.

How would I go about doing this?

That is how would I go about implementing own thread scheduler?


More information about the Python-Dev mailing list