diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2018-09-28 19:09:56 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-09-28 19:09:56 +0200 |
commit | cc888778bf49c6472b22ed7b5541e0c6e294c427 (patch) | |
tree | 97879e34027d59d45d3846cb3c1028488dcc77ff | |
parent | 1a7512f337a61733c0523b4199aa392b48a22ad6 (diff) | |
download | psutil-cc888778bf49c6472b22ed7b5541e0c6e294c427.tar.gz |
catch UnicodeEncodeError on print()
-rwxr-xr-x | scripts/pmap.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/scripts/pmap.py b/scripts/pmap.py index a509bd73..988b7507 100755 --- a/scripts/pmap.py +++ b/scripts/pmap.py @@ -35,6 +35,13 @@ import sys import psutil +def safe_print(s): + try: + print(s) + except UnicodeEncodeError: + print(s.encode('ascii', 'ignore').decode()) + + def main(): if len(sys.argv) != 2: sys.exit('usage: pmap <pid>') @@ -45,7 +52,7 @@ def main(): total_rss = 0 for m in p.memory_maps(grouped=False): total_rss += m.rss - print(templ % ( + safe_print(templ % ( m.addr.split('-')[0].zfill(16), str(m.rss / 1024) + 'K', m.perms, |