diff -r bf3a7373e11a Lib/cProfile.py --- a/Lib/cProfile.py Sat Dec 05 00:19:08 2015 -0600 +++ b/Lib/cProfile.py Sat Dec 05 21:16:29 2015 +0800 @@ -39,7 +39,9 @@ def print_stats(self, sort=-1): import pstats - pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats() + if not hasattr(sort, '__iter__') or isinstance(sort, str): + sort = (sort,) + pstats.Stats(self).strip_dirs().sort_stats(*sort).print_stats() def dump_stats(self, file): import marshal diff -r bf3a7373e11a Lib/profile.py --- a/Lib/profile.py Sat Dec 05 00:19:08 2015 -0600 +++ b/Lib/profile.py Sat Dec 05 21:16:29 2015 +0800 @@ -387,8 +387,9 @@ def print_stats(self, sort=-1): import pstats - pstats.Stats(self).strip_dirs().sort_stats(sort). \ - print_stats() + if not hasattr(sort, '__iter__') or isinstance(sort, str): + sort = (sort,) + pstats.Stats(self).strip_dirs().sort_stats(*sort).print_stats() def dump_stats(self, file): with open(file, 'wb') as f: diff -r bf3a7373e11a Lib/test/test_profile.py --- a/Lib/test/test_profile.py Sat Dec 05 00:19:08 2015 -0600 +++ b/Lib/test/test_profile.py Sat Dec 05 21:16:29 2015 +0800 @@ -86,6 +86,14 @@ self.profilermodule.run("int('1')", filename=TESTFN) self.assertTrue(os.path.exists(TESTFN)) + def test_run_with_sort_by_values(self): + s = StringIO() + stdout = sys.stdout + sys.stdout = s + self.profilermodule.run("int('1')", sort=('tottime', 'stdname')) + sys.stdout = stdout + self.assertIn("Ordered by: internal time, standard name", s.getvalue()) + def test_runctx(self): with silent(): self.profilermodule.runctx("testfunc()", globals(), locals())