Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
85e816c6
Commit
85e816c6
authored
Feb 11, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull our subprocess code out into a new pyrasite.utils module
parent
3543596c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
21 deletions
+36
-21
pyrasite/inject.py
pyrasite/inject.py
+5
-14
pyrasite/inspect.py
pyrasite/inspect.py
+4
-7
pyrasite/utils.py
pyrasite/utils.py
+27
-0
No files found.
pyrasite/inject.py
View file @
85e816c6
...
...
@@ -28,7 +28,10 @@ Authors:
David Malcolm <dmalcolm@redhat.com>
"""
import
os
,
subprocess
,
warnings
import
os
import
warnings
from
utils
import
run
class
CodeInjector
(
object
):
...
...
@@ -53,17 +56,5 @@ class CodeInjector(object):
'PyRun_SimpleString("execfile(
\
\
"%s
\
\
")")'
%
self
.
filename
,
'PyGILState_Release($1)'
,
]
self
.
_
run
(
'%sgdb -p %d -batch %s'
%
(
self
.
gdb_prefix
,
self
.
pid
,
run
(
'%sgdb -p %d -batch %s'
%
(
self
.
gdb_prefix
,
self
.
pid
,
' '
.
join
([
"-eval-command='call %s'"
%
cmd
for
cmd
in
gdb_cmds
])))
def
_run
(
self
,
cmd
):
if
self
.
verbose
:
print
(
cmd
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
()
if
self
.
verbose
:
print
(
out
)
if
err
:
print
(
err
)
pyrasite/inspect.py
View file @
85e816c6
...
...
@@ -15,7 +15,7 @@
#
# Copyright (C) 2011 Red Hat, Inc.
import
subprocess
from
utils
import
run
class
ObjectInspector
(
object
):
"""Inspects objects in a running Python program"""
...
...
@@ -24,13 +24,10 @@ class ObjectInspector(object):
self
.
pid
=
pid
def
inspect
(
self
,
address
):
cmd
=
[
cmd
=
' '
.
join
(
[
'gdb --quiet -p %s -batch'
%
self
.
pid
,
'-eval-command="print (PyObject *)%s"'
%
address
,
]
p
=
subprocess
.
Popen
(
' '
.
join
(
cmd
),
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
()
for
line
in
out
.
split
(
'
\
n
'
):
])
for
line
in
run
(
cmd
).
split
(
'
\
n
'
):
if
line
.
startswith
(
'$1 = '
):
return
line
[
5
:]
pyrasite/utils.py
0 → 100644
View file @
85e816c6
# This file is part of pyrasite.
#
# pyrasite is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyrasite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyrasite. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2011 Red Hat, Inc.
import
subprocess
,
warnings
def
run
(
cmd
):
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
()
if
err
:
warnings
.
warn
(
err
)
return
out
.
strip
()
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