You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57Lines changed: 57 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -554,6 +554,63 @@ if __name__ == "__main__":
554
554
</details>
555
555
556
556
557
+
<details>
558
+
<summary> ✅ Use a <code>Queue</code> as input for optimizing data</summary>
559
+
560
+
561
+
Sometimes you don’t have a static list of inputs to optimize — instead, you have a stream of data coming in over time. In such cases, you can use a multiprocessing.Queue to feed data into the optimize() function.
562
+
563
+
- This is especially useful when you're collecting data from a remote source like a web scraper, socket, or API.
564
+
565
+
- You can also use this setup to store `replay buffer` data during reinforcement learning and later stream it back for training.
566
+
567
+
```python
568
+
from multiprocessing import Process, Queue
569
+
from litdata.processing.data_processor importALL_DONE
570
+
import litdata as ld
571
+
import time
572
+
573
+
defyield_numbers():
574
+
for i inrange(1000):
575
+
time.sleep(0.01)
576
+
yield (i, i**2)
577
+
578
+
defdata_producer(q: Queue):
579
+
for item in yield_numbers():
580
+
q.put(item)
581
+
582
+
q.put(ALL_DONE) # Sentinel value to signal completion
0 commit comments