LKML Archive on
 help / color / Atom feed
From: Jiri Olsa <>
To: Arnaldo Carvalho de Melo <>
Cc: lkml <>,
	"Ingo Molnar" <>,
	"Namhyung Kim" <>,
	"Alexander Shishkin" <>,
	"Peter Zijlstra" <>,
	"Ondřej Lysoněk" <>
Subject: [PATCH] perf python: Do not force closing original perf descriptor in evlist.get_pollfd
Date: Wed, 26 Dec 2018 12:21:21 +0100
Message-ID: <> (raw)

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

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

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 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: Ondřej Lysoněk <>
Signed-off-by: Jiri Olsa <>
 tools/perf/util/python.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 47628e85c5eb..dda0ac978b1e 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -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,
+				     NULL, NULL, NULL, 0);
 		if (file == NULL)
 			goto free_list;

             reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-26 11:21 Jiri Olsa [this message]
2018-12-26 19:47 ` Arnaldo Carvalho de Melo
2018-12-27  8:06 ` Jiri Olsa
2018-12-27 12:54   ` Arnaldo Carvalho de Melo
2019-01-03 13:13 ` [tip:perf/urgent] perf python: Do not force closing original perf descriptor in evlist.get_pollfd() tip-bot for Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git
	git clone --mirror lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone