Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyperf API examples fail when running from a REPL #145

Closed
ngoldbaum opened this issue Nov 15, 2022 · 2 comments
Closed

Pyperf API examples fail when running from a REPL #145

ngoldbaum opened this issue Nov 15, 2022 · 2 comments

Comments

@ngoldbaum
Copy link
Contributor

When I try to run an example from the docs inside IPython or a regular python REPL, it fails with the following output:

$ ipython
Python 3.10.5 (main, Jul  4 2022, 10:24:08) [GCC 11.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pyperf
   ...: import time
   ...: 
   ...: 
   ...: def func():
   ...:     time.sleep(0.001)
   ...: 
   ...: 
   ...: runner = pyperf.Runner()
   ...: runner.bench_func('sleep', func)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'worker' is not defined
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [1], in <cell line: 10>()
      6     time.sleep(0.001)
      9 runner = pyperf.Runner()
---> 10 runner.bench_func('sleep', func)

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_runner.py:537, in Runner.bench_func(self, name, func, *args, **kwargs)
    535 task = WorkerProcessTask(self, name, task_func, metadata)
    536 task.inner_loops = inner_loops
--> 537 result = self._main(task)
    539 if self.args.profile:
    540     merge_profile_stats(profiler, self.args.profile)

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_runner.py:460, in Runner._main(self, task)
    458         bench = None
    459     else:
--> 460         bench = self._manager()
    461 except KeyboardInterrupt:
    462     what = "Benchmark worker" if args.worker else "Benchmark"

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_runner.py:668, in Runner._manager(self)
    666 if self.args.verbose and self._worker_task > 0:
    667     print()
--> 668 bench = Manager(self).create_bench()
    669 if not self.args.quiet:
    670     print()

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_manager.py:232, in Manager.create_bench(self)
    229     self.args.warmups = 1
    231 while self.nprocess < self.need_nprocess:
--> 232     worker_bench, run = self.create_worker_bench()
    233     self.display_run(worker_bench, run)
    234     self.handle_calibration(run)

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_manager.py:131, in Manager.create_worker_bench(self)
    130 def create_worker_bench(self):
--> 131     suite = self.create_suite()
    133     # get the run
    134     benchmarks = suite._benchmarks

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_manager.py:121, in Manager.create_suite(self)
    119 # compute the run
    120 if self.next_run == 'loops':
--> 121     suite = self.spawn_worker(self.calibrate_loops, 0)
    122 elif self.next_run == 'warmups':
    123     suite = self.spawn_worker(0, self.calibrate_warmups)

File ~/.pyenv/versions/3.10.5/lib/python3.10/site-packages/pyperf/_manager.py:107, in Manager.spawn_worker(self, calibrate_loops, calibrate_warmups)
    104         exitcode = proc.wait()
    106 if exitcode:
--> 107     raise RuntimeError("%s failed with exit code %s"
    108                        % (cmd[0], exitcode))
    110 return _load_suite_from_pipe(bench_json)

RuntimeError: /home/nathan/.pyenv/versions/3.10.5/bin/python3 failed with exit code 1
@ngoldbaum
Copy link
Contributor Author

It runs fine inside of a script though.

@ngoldbaum
Copy link
Contributor Author

oops, this is a repost of #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant