Commit c1d03fb1 authored by Jiri Olsa's avatar Jiri Olsa Committed by Greg Kroah-Hartman

perf python: Do not force closing original perf descriptor in evlist.get_pollfd()

[ Upstream commit a389aece ]

Ondřej reported that when compiled with python3, the python extension
regresses in evlist.get_pollfd function behaviour.

The evlist.get_pollfd function creates file objects from evlist's fds
and returns them in a list. The python3 version also sets them to 'close
the original descriptor' when the object dies (is closed), by passing
True via the 'closefd' arg in the PyFile_FromFd call.

The python's closefd doc says:

  If closefd is False, the underlying file descriptor will be kept open
  when the file is closed.

That's why the following line in python3 closes all evlist fds:


the returned list is immediately destroyed and that takes down the
original events fds.

Passing closefd as False to PyFile_FromFd to fix this.
Reported-by: olysonek's avatarOndřej Lysoněk <>
Signed-off-by: 's avatarJiri Olsa <>
Cc: Alexander Shishkin <>
Cc: Jaroslav Škarvada <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Fixes: 66dfdff0 ("perf tools: Add Python 3 support")
Link: 's avatarArnaldo Carvalho de Melo <>
Signed-off-by: 's avatarSasha Levin <>
parent 65ad8e0a
......@@ -939,7 +939,8 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_evlist *pevlist,
file = PyFile_FromFile(fp, "perf", "r", NULL);
file = PyFile_FromFd(evlist->pollfd.entries[i].fd, "perf", "r", -1, NULL, NULL, NULL, 1);
file = PyFile_FromFd(evlist->pollfd.entries[i].fd, "perf", "r", -1,
if (file == NULL)
goto free_list;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment