Thread-safe iterators 0 ▲ mathspp.com feed 2 hours ago · Tech · hide · 0 comments Learn how to write and use thread-safe iterators in Python 3.15. This article shows how to write and use iterators in a thread-safe manner using the new tools from Python 3.15: threading.serialize_iterator threading.synchronized_iterator 15 days of Python 3.15 To celebrate the release of Python 3.15, over the next 15 business days I'll be writing about a new 3.15 feature every day. Explained clearly and with examples so you don't have to sift through the changelog. Subscribe to receive this free email series: Enroll for free 🐍🚀 If you want, you can also check the schedule of the upcoming emails. Iterators are not thread-safe Most iterators are not thread-safe by default. For example, generator iterators can raise a ValueError if accessed simultaneously from two different threads, as you'll see now. First, you're going to define a slow generator: import time def slow_counter(): idx = 0 while True: time.sleep(1) idx += 1 yield idx counter = slow_counter() The generator counter takes a… No comments yet. Log in to reply on the Fediverse. Comments will appear here.