Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
DI-engine
提交
88658ea3
D
DI-engine
项目概览
OpenDILab开源决策智能平台
/
DI-engine
上一次同步 2 年多
通知
56
Star
321
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DI-engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
88658ea3
编写于
12月 27, 2021
作者:
X
Xu Jingxin
提交者:
GitHub
12月 27, 2021
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc(xjx): add docs, wrap decorators for framework (#166)
上级
0b71fc4e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
1 deletion
+57
-1
ding/framework/parallel.py
ding/framework/parallel.py
+20
-0
ding/framework/task.py
ding/framework/task.py
+35
-1
ding/worker/buffer/buffer.py
ding/worker/buffer/buffer.py
+2
-0
未找到文件。
ding/framework/parallel.py
浏览文件 @
88658ea3
...
...
@@ -207,13 +207,33 @@ now there are {} ports and {} workers".format(len(ports), n_workers)
break
def
register_rpc
(
self
,
fn_name
:
str
,
fn
:
Callable
)
->
None
:
"""
Overview:
Register an rpc on parallel instance, this function will be executed
\
when a remote process call this function via network.
Arguments:
- fn_name (:obj:`str`): Function name.
- fn (:obj:`Callable`): Function body.
"""
self
.
_rpc
[
fn_name
]
=
fn
def
unregister_rpc
(
self
,
fn_name
:
str
)
->
None
:
"""
Overview:
Unregister an rpc function.
Arguments:
- fn_name (:obj:`str`): Function name.
"""
if
fn_name
in
self
.
_rpc
:
del
self
.
_rpc
[
fn_name
]
def
send_rpc
(
self
,
func_name
:
str
,
*
args
,
**
kwargs
)
->
None
:
"""
Overview:
Send an rpc via network to subscribed processes.
Arguments:
- fn_name (:obj:`str`): Function name.
"""
if
self
.
is_active
:
payload
=
{
"f"
:
func_name
,
"a"
:
args
,
"k"
:
kwargs
}
return
self
.
_sock
and
self
.
_sock
.
send
(
pickle
.
dumps
(
payload
,
protocol
=-
1
))
...
...
ding/framework/task.py
浏览文件 @
88658ea3
...
...
@@ -8,6 +8,7 @@ from types import GeneratorType
from
typing
import
Awaitable
,
Callable
,
Dict
,
Generator
,
Iterable
,
List
,
Optional
,
Set
from
ding.framework.context
import
Context
from
ding.framework.parallel
import
Parallel
from
functools
import
wraps
def
enable_async
(
func
:
Callable
)
->
Callable
:
...
...
@@ -20,6 +21,7 @@ def enable_async(func: Callable) -> Callable:
- runtime_handler (:obj:`Callable`): The wrap function.
"""
@
wraps
(
func
)
def
runtime_handler
(
task
:
"Task"
,
*
args
,
**
kwargs
)
->
"Task"
:
"""
Overview:
...
...
@@ -115,6 +117,13 @@ class Task:
return
self
def
use_step_wrapper
(
self
,
fn
:
Callable
)
->
'Task'
:
"""
Overview:
Register wrappers to task. A wrapper works like a decorator, but task will apply this
\
decorator on top of each middleware.
Arguments:
- fn (:obj:`Callable`): A wrapper is a decorator, so the first argument is a callable function.
"""
self
.
step_wrappers
.
append
(
fn
)
return
self
...
...
@@ -227,6 +236,10 @@ class Task:
self
.
stop
()
def
stop
(
self
)
->
None
:
"""
Overview:
Stop and cleanup every thing in the runtime of task.
"""
self
.
emit
(
"exit"
)
if
self
.
_thread_pool
:
self
.
_thread_pool
.
shutdown
()
...
...
@@ -284,7 +297,14 @@ be thrown after the timeout {}s is reached".format(n_timeout)
t
=
self
.
_loop
.
run_in_executor
(
self
.
_thread_pool
,
fn
,
*
args
,
**
kwargs
)
self
.
_async_stack
.
append
(
t
)
def
emit
(
self
,
event_name
,
*
args
,
**
kwargs
):
def
emit
(
self
,
event_name
:
str
,
*
args
,
**
kwargs
):
"""
Overview:
Emit a event, call listeners.
Arguments:
- event_name (:obj:`str`): Event name.
- args (:obj:`any`): Rest arguments for listeners.
"""
if
event_name
in
self
.
event_listeners
:
for
fn
in
self
.
event_listeners
[
event_name
]:
fn
(
*
args
,
**
kwargs
)
...
...
@@ -294,9 +314,23 @@ be thrown after the timeout {}s is reached".format(n_timeout)
fn
(
*
args
,
**
kwargs
)
def
on
(
self
,
event
:
str
,
fn
:
Callable
)
->
None
:
"""
Overview:
Subscribe to an event, execute this function every time the event is emitted.
Arguments:
- event (:obj:`str`): Event name.
- fn (:obj:`Callable`): The function.
"""
self
.
event_listeners
[
event
].
append
(
fn
)
def
once
(
self
,
event
:
str
,
fn
:
Callable
)
->
None
:
"""
Overview:
Subscribe to an event, execute this function only once when the event is emitted.
Arguments:
- event (:obj:`str`): Event name.
- fn (:obj:`Callable`): The function.
"""
self
.
once_listeners
[
event
].
append
(
fn
)
@
property
...
...
ding/worker/buffer/buffer.py
浏览文件 @
88658ea3
...
...
@@ -2,12 +2,14 @@ from abc import abstractmethod
from
typing
import
Any
,
List
,
Optional
,
Union
,
Callable
import
copy
from
dataclasses
import
dataclass
from
functools
import
wraps
def
apply_middleware
(
func_name
:
str
):
def
wrap_func
(
base_func
:
Callable
):
@
wraps
(
base_func
)
def
handler
(
buffer
,
*
args
,
**
kwargs
):
"""
Overview:
...
...
OpenDILab开源决策智能平台
@m0_55289267
mentioned in commit
d23047db
·
12月 28, 2021
mentioned in commit
d23047db
mentioned in commit d23047db14e7535b76ce5ac7cfe2072cf9c821e9
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录