Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
66d973bd
提交
66d973bd
authored
3月 14, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
3月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure the first thread obtains the lock first in test_locking_thread
上级
7579a8cd
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
4 行删除
+25
-4
test_compilelock.py
tests/compile/test_compilelock.py
+25
-4
没有找到文件。
tests/compile/test_compilelock.py
浏览文件 @
66d973bd
...
@@ -81,13 +81,22 @@ def run_locking_test(ctx):
...
@@ -81,13 +81,22 @@ def run_locking_test(ctx):
def
test_locking_thread
():
def
test_locking_thread
():
import
traceback
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
def
test_fn_1
():
def
test_fn_1
(
arg
):
try
:
with
lock_ctx
(
dir_name
):
with
lock_ctx
(
dir_name
):
# Sleep "indefinitely"
# Notify the outside that we've obtained the lock
time
.
sleep
(
100
)
arg
.
append
(
False
)
while
True
not
in
arg
:
time
.
sleep
(
0.5
)
except
Exception
:
# Notify the outside that we done
arg
.
append
(
False
)
# If something unexpected happened, we want to know what it was
traceback
.
print_exc
()
def
test_fn_2
(
arg
):
def
test_fn_2
(
arg
):
try
:
try
:
...
@@ -98,18 +107,30 @@ def test_locking_thread():
...
@@ -98,18 +107,30 @@ def test_locking_thread():
# It timed out, which means that the lock was still held by the
# It timed out, which means that the lock was still held by the
# first thread
# first thread
arg
.
append
(
True
)
arg
.
append
(
True
)
except
Exception
:
# If something unexpected happened, we want to know what it was
traceback
.
print_exc
()
thread_1
=
threading
.
Thread
(
target
=
test_fn_1
)
res
=
[]
res
=
[]
thread_1
=
threading
.
Thread
(
target
=
test_fn_1
,
args
=
(
res
,))
thread_2
=
threading
.
Thread
(
target
=
test_fn_2
,
args
=
(
res
,))
thread_2
=
threading
.
Thread
(
target
=
test_fn_2
,
args
=
(
res
,))
thread_1
.
start
()
thread_1
.
start
()
# Make sure the first thread has obtained the lock
while
False
not
in
res
:
time
.
sleep
(
0.5
)
thread_2
.
start
()
thread_2
.
start
()
# The second thread should raise `filelock.Timeout`
# The second thread should raise `filelock.Timeout`
thread_2
.
join
()
thread_2
.
join
()
assert
True
in
res
assert
True
in
res
thread_1
.
join
()
assert
not
thread_1
.
is_alive
()
assert
not
thread_2
.
is_alive
()
@pytest.mark.skipif
(
sys
.
platform
!=
"linux"
,
reason
=
"Fork is only available on linux"
)
@pytest.mark.skipif
(
sys
.
platform
!=
"linux"
,
reason
=
"Fork is only available on linux"
)
def
test_locking_multiprocess_fork
():
def
test_locking_multiprocess_fork
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论