@@ -166,7 +166,6 @@ def __init__(
166
166
max_concurrent : Optional [int ],
167
167
snapshot_frequency : int ,
168
168
initial_state : Optional [Dict [str , Any ]],
169
- daemonic_reading : bool ,
170
169
):
171
170
self .source = source
172
171
self .map_fn = map_fn
@@ -175,7 +174,6 @@ def __init__(
175
174
self .method = method
176
175
self .mp_context = mp_context
177
176
self .snapshot_frequency = snapshot_frequency
178
- self .daemonic_reading = daemonic_reading
179
177
180
178
self ._in_q : Union [queue .Queue , mp .Queue ] = queue .Queue () if method == "thread" else mp_context .Queue ()
181
179
self ._intermed_q : Union [queue .Queue , mp .Queue ] = queue .Queue () if method == "thread" else mp_context .Queue ()
@@ -209,7 +207,7 @@ def __init__(
209
207
self ._stop ,
210
208
),
211
209
name = "read_thread(target=_populate_queue)" ,
212
- daemon = self . daemonic_reading ,
210
+ daemon = False ,
213
211
)
214
212
self ._read_thread .start ()
215
213
@@ -249,7 +247,7 @@ def __init__(
249
247
self ._sort_q ,
250
248
self ._stop ,
251
249
),
252
- daemon = True ,
250
+ daemon = False ,
253
251
name = "sort_thread(target=_sort_worker)" ,
254
252
)
255
253
self ._out_q = self ._sort_q
@@ -352,7 +350,6 @@ def __init__(
352
350
multiprocessing_context : Optional [str ] = None ,
353
351
max_concurrent : Optional [int ] = None ,
354
352
snapshot_frequency : int = 1 ,
355
- daemonic_reading : bool = True ,
356
353
):
357
354
super ().__init__ ()
358
355
assert method in ["thread" , "process" ]
@@ -371,7 +368,6 @@ def __init__(
371
368
raise ValueError (f"{ max_concurrent = } should be <= { num_workers = } !" )
372
369
self .max_concurrent = max_concurrent
373
370
self .snapshot_frequency = snapshot_frequency
374
- self .daemonic_reading = daemonic_reading
375
371
self ._it : Optional [Union [_InlineMapperIter [T ], _ParallelMapperIter [T ]]] = None
376
372
377
373
def reset (self , initial_state : Optional [Dict [str , Any ]] = None ):
@@ -399,7 +395,6 @@ def _parallel_reset(self, initial_state: Optional[Dict[str, Any]]):
399
395
max_concurrent = self .max_concurrent ,
400
396
snapshot_frequency = self .snapshot_frequency ,
401
397
initial_state = initial_state ,
402
- daemonic_reading = self .daemonic_reading ,
403
398
)
404
399
405
400
def next (self ) -> T :
@@ -448,7 +443,6 @@ def __init__(
448
443
max_concurrent : Optional [int ] = None ,
449
444
snapshot_frequency : int = 1 ,
450
445
prebatch : Optional [int ] = None ,
451
- daemonic_reading : bool = True ,
452
446
):
453
447
super ().__init__ ()
454
448
assert method in ["thread" , "process" ]
@@ -462,7 +456,6 @@ def __init__(
462
456
self .max_concurrent = max_concurrent
463
457
self .snapshot_frequency = snapshot_frequency
464
458
self .prebatch = prebatch
465
- self .daemonic_reading = daemonic_reading
466
459
if prebatch is None :
467
460
self .map_fn = map_fn
468
461
self .source = source
@@ -481,7 +474,6 @@ def __init__(
481
474
multiprocessing_context = self .multiprocessing_context ,
482
475
max_concurrent = self .max_concurrent ,
483
476
snapshot_frequency = self .snapshot_frequency ,
484
- daemonic_reading = self .daemonic_reading ,
485
477
)
486
478
487
479
if self .prebatch is None :
@@ -581,7 +573,7 @@ def __init__(
581
573
self ._sem ,
582
574
self ._stop_event ,
583
575
),
584
- daemon = True ,
576
+ daemon = False ,
585
577
name = f"worker_thread(target={ self .worker .__name__ } )" ,
586
578
)
587
579
self ._thread .start ()
@@ -605,6 +597,7 @@ def __iter__(self) -> Iterator[T]:
605
597
def __next__ (self ) -> T :
606
598
while True :
607
599
if self ._stop_event .is_set ():
600
+ self ._shutdown ()
608
601
raise StopIteration ()
609
602
try :
610
603
item , idx = self ._q .get (block = True , timeout = QUEUE_TIMEOUT )
@@ -614,11 +607,13 @@ def __next__(self) -> T:
614
607
if isinstance (item , StopIteration ):
615
608
self ._sem .release ()
616
609
self ._stop_event .set ()
610
+ self ._shutdown ()
617
611
raise item
618
612
elif isinstance (item , ExceptionWrapper ):
619
613
if not isinstance (item , StartupExceptionWrapper ):
620
614
# We don't need to release for startup exceptions
621
615
self ._sem .release ()
616
+ self ._shutdown ()
622
617
self ._stop_event .set ()
623
618
item .reraise ()
624
619
else :
0 commit comments