File tree Expand file tree Collapse file tree 1 file changed +23
-10
lines changed Expand file tree Collapse file tree 1 file changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -170,16 +170,29 @@ def start():
170
170
171
171
@pytest .fixture
172
172
def loop_in_thread (cleanup ):
173
- with pristine_loop () as loop :
174
- thread = threading .Thread (target = loop .start , name = "test IOLoop" )
175
- thread .daemon = True
176
- thread .start ()
177
- loop_started = threading .Event ()
178
- loop .add_callback (loop_started .set )
179
- loop_started .wait ()
180
- yield loop
181
- loop .add_callback (loop .stop )
182
- thread .join (timeout = 5 )
173
+ loop_started = concurrent .futures .Future ()
174
+ with concurrent .futures .ThreadPoolExecutor (
175
+ 1 , thread_name_prefix = "test IOLoop"
176
+ ) as tpe :
177
+
178
+ async def run ():
179
+ io_loop = IOLoop .current ()
180
+ stop_event = asyncio .Event ()
181
+ loop_started .set_result ((io_loop , stop_event ))
182
+ await stop_event .wait ()
183
+
184
+ ran = tpe .submit (_run_and_close_tornado , run )
185
+ for f in concurrent .futures .as_completed ((loop_started , ran )):
186
+ if f is loop_started :
187
+ io_loop , stop_event = loop_started .result ()
188
+ try :
189
+ yield io_loop
190
+ finally :
191
+ io_loop .add_callback (stop_event .set )
192
+
193
+ elif f is ran :
194
+ ran .result ()
195
+ return
183
196
184
197
185
198
@pytest .fixture
You can’t perform that action at this time.
0 commit comments