Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
c80fd613
Commit
c80fd613
authored
Jul 16, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add pdb shell
parent
8dbe9829
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
tensorpack/callbacks/stats.py
tensorpack/callbacks/stats.py
+16
-6
No files found.
tensorpack/callbacks/stats.py
View file @
c80fd613
...
...
@@ -29,28 +29,38 @@ class SendStat(Callback):
logger
.
error
(
"Command {} failed with ret={}!"
.
format
(
cmd
,
ret
))
# TODO other types of shell?
class
InjectShell
(
Callback
):
"""
When triggered, opens an IPython shell if a file exists.
When triggered, opens an IPython
/pdb
shell if a file exists.
Useful for interactive debug during training.
Using this callback requires ipython to be installed.
"""
def
__init__
(
self
,
file
=
'INJECT_SHELL.tmp'
):
def
__init__
(
self
,
file
=
'INJECT_SHELL.tmp'
,
shell
=
'ipython'
):
"""
Args:
file (str): if this file exists, will open a shell.
shell (str): one of 'ipython', 'pdb'
"""
self
.
_file
=
file
logger
.
info
(
"Create a file '{}' to open debug shell."
.
format
(
file
))
assert
shell
in
[
'ipython'
,
'pdb'
]
self
.
_shell
=
shell
logger
.
info
(
"Create a file '{}' to open {} shell."
.
format
(
file
,
shell
))
def
_trigger
(
self
):
if
os
.
path
.
isfile
(
self
.
_file
):
logger
.
info
(
"File {} exists, entering shell."
.
format
(
self
.
_file
))
trainer
=
self
.
trainer
# noqa
import
IPython
as
IP
;
IP
.
embed
()
# noqa
self
.
_inject
()
def
_inject
(
self
):
trainer
=
self
.
trainer
# noqa
if
self
.
_shell
==
'ipython'
:
import
IPython
as
IP
# noqa
IP
.
embed
()
elif
self
.
_shell
==
'pdb'
:
import
pdb
# noqa
pdb
.
set_trace
()
def
_after_train
(
self
):
if
os
.
path
.
isfile
(
self
.
_file
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment