Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
91ffe60b
提交
91ffe60b
authored
12月 29, 2020
作者:
Michael Osthege
提交者:
Brandon T. Willard
1月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for theano.compile.compilelock
上级
0fa004e1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
1 行删除
+90
-1
test_compilelock.py
tests/compile/test_compilelock.py
+89
-0
compilelock.py
theano/compile/compilelock.py
+1
-1
没有找到文件。
tests/compile/test_compilelock.py
0 → 100644
浏览文件 @
91ffe60b
import
multiprocessing
import
os
import
sys
import
tempfile
import
filelock
import
pytest
from
theano.compile.compilelock
import
force_unlock
,
local_mem
,
lock_ctx
def
test_compilelock_errors
():
with
tempfile
.
TemporaryDirectory
()
as
dir
:
with
pytest
.
raises
(
ValueError
):
with
lock_ctx
(
dir
,
timeout
=
0
):
pass
with
pytest
.
raises
(
ValueError
):
with
lock_ctx
(
dir
,
timeout
=-
2
):
pass
def
test_compilelock_force_unlock
():
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
with
lock_ctx
(
dir_name
):
dir_key
=
f
"{dir_name}-{os.getpid()}"
assert
dir_key
in
local_mem
.
_locks
assert
local_mem
.
_locks
[
dir_key
]
force_unlock
(
dir_name
)
assert
dir_key
not
in
local_mem
.
_locks
# A sub-process forcing unlock...
ctx
=
multiprocessing
.
get_context
(
"spawn"
)
p
=
ctx
.
Process
(
target
=
force_unlock
,
args
=
(
dir_name
,))
p
.
start
()
p
.
join
()
assert
dir_key
not
in
local_mem
.
_locks
def
check_is_locked
(
dir_name
,
q
):
try
:
with
lock_ctx
(
dir_name
,
timeout
=
0.1
):
q
.
put
(
"unlocked"
)
except
filelock
.
Timeout
:
q
.
put
(
"locked"
)
def
get_subprocess_lock_state
(
ctx
,
dir_name
):
q
=
ctx
.
Queue
()
p
=
ctx
.
Process
(
target
=
check_is_locked
,
args
=
(
dir_name
,
q
))
p
.
start
()
result
=
q
.
get
()
p
.
join
()
return
result
def
run_locking_test
(
ctx
):
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"unlocked"
# create a lock on the test directory
with
lock_ctx
(
dir_name
):
dir_key
=
f
"{dir_name}-{os.getpid()}"
assert
dir_key
in
local_mem
.
_locks
assert
local_mem
.
_locks
[
dir_key
]
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"locked"
with
lock_ctx
(
dir_name
,
timeout
=
0.1
):
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"locked"
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"locked"
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"unlocked"
@pytest.mark.skipif
(
sys
.
platform
!=
"linux"
,
reason
=
"Fork is only available on linux"
)
def
test_locking_multiprocess_fork
():
ctx
=
multiprocessing
.
get_context
(
"fork"
)
run_locking_test
(
ctx
)
def
test_locking_multiprocess_spawn
():
ctx
=
multiprocessing
.
get_context
(
"spawn"
)
run_locking_test
(
ctx
)
theano/compile/compilelock.py
浏览文件 @
91ffe60b
...
@@ -57,7 +57,7 @@ def lock_ctx(lock_dir: os.PathLike = None, *, timeout: typing.Optional[float] =
...
@@ -57,7 +57,7 @@ def lock_ctx(lock_dir: os.PathLike = None, *, timeout: typing.Optional[float] =
lock_dir
=
config
.
compiledir
lock_dir
=
config
.
compiledir
if
timeout
==
-
1
:
if
timeout
==
-
1
:
timeout
=
config
.
compile__timeout
timeout
=
config
.
compile__timeout
elif
timeout
is
not
None
or
timeout
<=
0
:
elif
not
(
timeout
is
None
or
timeout
>
0
)
:
raise
ValueError
(
f
"Timeout parameter must be None or positive. Got {timeout}."
)
raise
ValueError
(
f
"Timeout parameter must be None or positive. Got {timeout}."
)
# locks are kept in a dictionary to account for changing compiledirs
# locks are kept in a dictionary to account for changing compiledirs
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论