@@ -133,15 +133,20 @@ def test_run_concurrently_sequence(are_subshells, overlap):
133
133
create_subshell_helper (kc )["subshell_id" ] if is_subshell else None
134
134
for is_subshell in are_subshells
135
135
]
136
+
137
+ # Import time module before running time-sensitive subshell code.
138
+ execute_request_subshell_id (kc , "import time; print('ok')" , None )
139
+
140
+ sleep = 0.2
136
141
if overlap :
137
142
codes = [
138
- "import time; start0=True; end0=False; time.sleep(0.2 ); end0=True" ,
139
- " assert start0; assert not end0; time.sleep(0.2 ); assert end0" ,
143
+ f" start0=True; end0=False; time.sleep({ sleep } ); end0=True" ,
144
+ f"time.sleep( { sleep / 2 } ); assert start0; assert not end0; time.sleep({ sleep } ); assert end0" ,
140
145
]
141
146
else :
142
147
codes = [
143
- "import time; start0=True; end0=False; time.sleep(0.2 ); assert end1" ,
144
- " assert start0; assert not end0; end1=True" ,
148
+ f" start0=True; end0=False; time.sleep({ sleep } ); assert end1" ,
149
+ f"time.sleep( { sleep / 2 } ); assert start0; assert not end0; end1=True" ,
145
150
]
146
151
147
152
msgs = []
@@ -150,8 +155,6 @@ def test_run_concurrently_sequence(are_subshells, overlap):
150
155
msg ["header" ]["subshell_id" ] = subshell_id
151
156
kc .shell_channel .send (msg )
152
157
msgs .append (msg )
153
- if len (msgs ) == 1 :
154
- time .sleep (0.1 ) # Wait for first execute_request to start.
155
158
156
159
replies = get_replies (kc , [msg ["msg_id" ] for msg in msgs ])
157
160
@@ -171,13 +174,16 @@ def test_run_concurrently_timing(include_main_shell):
171
174
create_subshell_helper (kc )["subshell_id" ],
172
175
]
173
176
177
+ # Import time module before running time-sensitive subshell code.
178
+ execute_request_subshell_id (kc , "import time; print('ok')" , None )
179
+
174
180
times = (0.2 , 0.2 )
175
181
# Prepare messages, times are sleep times in seconds.
176
182
# Identical times for both subshells is a harder test as preparing and sending
177
183
# the execute_reply messages may overlap.
178
184
msgs = []
179
185
for id , sleep in zip (subshell_ids , times ):
180
- code = f"import time; time.sleep({ sleep } )"
186
+ code = f"time.sleep({ sleep } )"
181
187
msg = kc .session .msg ("execute_request" , {"code" : code })
182
188
msg ["header" ]["subshell_id" ] = id
183
189
msgs .append (msg )
0 commit comments