The default threading model is already serializing all requests, but implementing thread_model() gives us good place to explain why the code works and why we don't use os.preadv and os.pwritev. --- plugins/python/examples/error.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/python/examples/error.py b/plugins/python/examples/error.py index 0331a83e..5cb368d2 100644 --- a/plugins/python/examples/error.py +++ b/plugins/python/examples/error.py @@ -11,33 +11,41 @@ # ./nbdkit -f -v python ./plugins/python/examples/error.py file=test.img # # Or run it after installing nbdkit like this: # # nbdkit -f -v python ./plugins/python/examples/error.py file=test.img # # The -f -v arguments are optional. They cause the server to stay in # the foreground and print debugging, which is useful when testing. import os +import nbdkit API_VERSION = 2 filename = None calls = 0 def config(key, value): global filename assert key == "file" filename = value +def thread_model(): + # Serialize all requests so we can seek safely in pread and pwrite + # and be compatible with python 3.6. In python 3.7 we can use + # os.preadv and os.pwritev and use the parallel threading model. + return nbdkit.THREAD_MODEL_SERIALIZE_ALL_REQUESTS + + def open(readonly): flags = os.O_RDONLY if readonly else os.O_RDWR return {"fd": os.open(filename, flags)} def can_extents(h): return True def get_size(h): -- 2.34.1