Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ebaad559
提交
ebaad559
authored
1月 22, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix a bug involving thread local memory initialization
上级
39af8a86
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
2 行删除
+39
-2
test_compilelock.py
tests/compile/test_compilelock.py
+33
-0
compilelock.py
theano/compile/compilelock.py
+6
-2
没有找到文件。
tests/compile/test_compilelock.py
浏览文件 @
ebaad559
...
...
@@ -2,6 +2,8 @@ import multiprocessing
import
os
import
sys
import
tempfile
import
threading
import
time
import
filelock
import
pytest
...
...
@@ -78,6 +80,37 @@ def run_locking_test(ctx):
assert
get_subprocess_lock_state
(
ctx
,
dir_name
)
==
"unlocked"
def
test_locking_thread
():
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
def
test_fn_1
():
with
lock_ctx
(
dir_name
):
# Sleep "indefinitely"
time
.
sleep
(
100
)
def
test_fn_2
(
arg
):
try
:
with
lock_ctx
(
dir_name
,
timeout
=
0.1
):
# If this can get the lock, then our file lock has failed
raise
AssertionError
()
except
filelock
.
Timeout
:
# It timed out, which means that the lock was still held by the
# first thread
arg
.
append
(
True
)
thread_1
=
threading
.
Thread
(
target
=
test_fn_1
)
res
=
[]
thread_2
=
threading
.
Thread
(
target
=
test_fn_2
,
args
=
(
res
,))
thread_1
.
start
()
thread_2
.
start
()
# The second thread should raise `filelock.Timeout`
thread_2
.
join
()
assert
True
in
res
@pytest.mark.skipif
(
sys
.
platform
!=
"linux"
,
reason
=
"Fork is only available on linux"
)
def
test_locking_multiprocess_fork
():
ctx
=
multiprocessing
.
get_context
(
"fork"
)
...
...
theano/compile/compilelock.py
浏览文件 @
ebaad559
...
...
@@ -18,8 +18,12 @@ __all__ = [
]
local_mem
=
threading
.
local
()
local_mem
.
_locks
:
typing
.
Dict
[
str
,
bool
]
=
{}
class
ThreadFileLocks
(
threading
.
local
):
def
__init__
(
self
):
self
.
_locks
=
{}
local_mem
=
ThreadFileLocks
()
def
force_unlock
(
lock_dir
:
os
.
PathLike
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论