Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PARL
提交
74d4facb
P
PARL
项目概览
PaddlePaddle
/
PARL
通知
67
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PARL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
74d4facb
编写于
8月 17, 2020
作者:
B
Bo Zhou
提交者:
GitHub
8月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support jupyter (#385)
* support jupyter * Update utils.py * Update utils.py
上级
d6e82f01
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
39 addition
and
25 deletion
+39
-25
parl/remote/client.py
parl/remote/client.py
+9
-16
parl/remote/utils.py
parl/remote/utils.py
+13
-8
parl/utils/utils.py
parl/utils/utils.py
+17
-1
未找到文件。
parl/remote/client.py
浏览文件 @
74d4facb
...
...
@@ -19,7 +19,7 @@ import socket
import
sys
import
threading
import
zmq
from
parl.utils
import
to_str
,
to_byte
,
get_ip_address
,
logger
from
parl.utils
import
to_str
,
to_byte
,
get_ip_address
,
logger
,
isnotebook
from
parl.remote
import
remote_constants
import
time
...
...
@@ -94,6 +94,9 @@ class Client(object):
pyfiles
[
'python_files'
]
=
{}
pyfiles
[
'other_files'
]
=
{}
if
isnotebook
():
main_folder
=
'./'
else
:
main_file
=
sys
.
argv
[
0
]
main_folder
=
'./'
sep
=
os
.
sep
...
...
@@ -108,16 +111,6 @@ class Client(object):
with
open
(
file_path
,
'rb'
)
as
code_file
:
code
=
code_file
.
read
()
pyfiles
[
'python_files'
][
file_name
]
=
code
# append entry file to code list
assert
os
.
path
.
isfile
(
main_file
),
"[xparl] error occurs when distributing files. cannot find the entry file:{} in current working directory: {}"
.
format
(
main_file
,
os
.
getcwd
())
with
open
(
main_file
,
'rb'
)
as
code_file
:
code
=
code_file
.
read
()
# parl/remote/remote_decorator.py -> remote_decorator.py
file_name
=
main_file
.
split
(
os
.
sep
)[
-
1
]
pyfiles
[
'python_files'
][
file_name
]
=
code
for
file_name
in
distributed_files
:
assert
os
.
path
.
exists
(
file_name
)
...
...
parl/remote/utils.py
浏览文件 @
74d4facb
...
...
@@ -14,6 +14,7 @@
import
sys
from
contextlib
import
contextmanager
import
os
from
parl.utils
import
isnotebook
__all__
=
[
'load_remote_class'
,
'redirect_stdout_to_file'
,
'locate_remote_file'
...
...
@@ -107,6 +108,7 @@ def redirect_stdout_to_file(file_path):
def
locate_remote_file
(
module_path
):
"""xparl has to locate the file that has the class decorated by parl.remote_class.
This function returns the relative path between this file and the entry file.
Note that this function should support the jupyter-notebook environment.
Args:
module_path: Absolute path of the module.
...
...
@@ -116,6 +118,9 @@ def locate_remote_file(module_path):
entry_file: /home/user/dir/main.py
--------> relative_path: subdir/my_module
"""
if
isnotebook
():
entry_path
=
os
.
getcwd
()
else
:
entry_file
=
sys
.
argv
[
0
]
entry_file
=
entry_file
.
split
(
os
.
sep
)[
-
1
]
entry_path
=
None
...
...
parl/utils/utils.py
浏览文件 @
74d4facb
...
...
@@ -20,7 +20,7 @@ import numpy as np
__all__
=
[
'has_func'
,
'to_str'
,
'to_byte'
,
'is_PY2'
,
'is_PY3'
,
'MAX_INT32'
,
'_HAS_FLUID'
,
'_HAS_TORCH'
,
'_IS_WINDOWS'
,
'_IS_MAC'
,
'kill_process'
,
'get_fluid_version'
'get_fluid_version'
,
'isnotebook'
]
...
...
@@ -101,3 +101,19 @@ def kill_process(regex_pattern):
command
=
"ps aux | grep {} | awk '{{print $2}}' | xargs kill -9"
.
format
(
regex_pattern
)
subprocess
.
call
([
command
],
shell
=
True
)
def
isnotebook
():
"""check if the code is excuted in the IPython notebook
Reference: https://stackoverflow.com/a/39662359
"""
try
:
shell
=
get_ipython
().
__class__
.
__name__
if
shell
==
'ZMQInteractiveShell'
:
return
True
# Jupyter notebook or qtconsole
elif
shell
==
'TerminalInteractiveShell'
:
return
False
# Terminal running IPython
else
:
return
False
# Other type (?)
except
NameError
:
return
False
# Probably standard Python interpreter
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录