@@ -140,8 +140,11 @@ def _deferred_from_coro(cls, coro) -> Deferred:
140140 return dfd
141141
142142 @classmethod
143- def start (cls , caller_id : int ) -> None :
144- cls ._stop_events [caller_id ] = asyncio .Event ()
143+ def start (cls , download_handler_id : int ) -> None :
144+ """Start the event loop in a new thread if not already started.
145+ Should be called from the Scrapy thread.
146+ """
147+ cls ._stop_events [download_handler_id ] = asyncio .Event ()
145148 if not getattr (cls , "_loop" , None ):
146149 policy = asyncio .DefaultEventLoopPolicy ()
147150 if platform .system () == "Windows" :
@@ -155,9 +158,11 @@ def start(cls, caller_id: int) -> None:
155158 asyncio .run_coroutine_threadsafe (cls ._process_queue (), cls ._loop )
156159
157160 @classmethod
158- def stop (cls , caller_id : int ) -> None :
159- """Wait until all handlers are closed to stop the event loop and join the thread."""
160- cls ._stop_events [caller_id ].set ()
161+ def stop (cls , download_handler_id : int ) -> None :
162+ """Wait until all handlers are closed to stop the event loop and join the thread.
163+ Should be called from the Scrapy thread.
164+ """
165+ cls ._stop_events [download_handler_id ].set ()
161166 if all (ev .is_set () for ev in cls ._stop_events .values ()):
162167 asyncio .run_coroutine_threadsafe (cls ._coro_queue .join (), cls ._loop )
163168 cls ._loop .call_soon_threadsafe (cls ._loop .stop )
0 commit comments