Skip to content

Commit

Permalink
Merge pull request iovisor#1393 from pchaigno/handle-epipe
Browse files Browse the repository at this point in the history
Exit on EPIPE
  • Loading branch information
4ast authored Oct 26, 2017
2 parents 1e7dc39 + 860dbb0 commit fbbe6d6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/python/bcc/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from functools import reduce
import multiprocessing
import os
import errno

from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE
from .perf import Perf
Expand Down Expand Up @@ -523,8 +524,24 @@ def open_perf_buffer(self, callback, page_cnt=8, lost_cb=None):
self._open_perf_buffer(i, callback, page_cnt, lost_cb)

def _open_perf_buffer(self, cpu, callback, page_cnt, lost_cb):
fn = _RAW_CB_TYPE(lambda _, data, size: callback(cpu, data, size))
lost_fn = _LOST_CB_TYPE(lambda lost: lost_cb(lost)) if lost_cb else ct.cast(None, _LOST_CB_TYPE)
def raw_cb_(_, data, size):
try:
callback(cpu, data, size)
except IOError, e:
if e.errno == errno.EPIPE:
exit()
else:
raise e
def lost_cb_(lost):
try:
lost_cb(lost)
except IOError, e:
if e.errno == errno.EPIPE:
exit()
else:
raise e
fn = _RAW_CB_TYPE(raw_cb_)
lost_fn = _LOST_CB_TYPE(lost_cb_) if lost_cb else ct.cast(None, _LOST_CB_TYPE)
reader = lib.bpf_open_perf_buffer(fn, lost_fn, None, -1, cpu, page_cnt)
if not reader:
raise Exception("Could not open perf buffer")
Expand Down

0 comments on commit fbbe6d6

Please sign in to comment.