Skip to content
This repository

Reset execution counter after cache is cleared #712

Closed
wants to merge 1 commit into from

2 participants

Stefan van der Walt Thomas Kluyver
Stefan van der Walt

This is to prevent the counter from shooting up much above 1000 (the cache limit). If the counter is not reset, it keeps growing forever.

Please review this change carefully: I do not know if changing the execution counter has any other effect, and can simply verify that this brings the prompt back to 1 after clearing the cache (but I do believe this is the right thing to do, given that the cache is cleared out).

Thomas Kluyver
Collaborator

I don't think this is a good idea, unfortunately. The execution count is used to index lines in the input history, which doesn't get reset when this cache is flushed.

Conceptually, the prompt number is your position in your session, which isn't affected by the cache being flushed. I'd find it very offputting if it suddenly reset itself, because that implies that I'm starting with a fresh session. Looking at the file, we should probably reword the warning message that shows up when you reach the cache size.

In fact, I think there's a better solution than this. This system, without any prior warning, drops all but the last three items in history, which could be annoying if it happens at a critical moment. How about, on reaching the cache size, we drop the oldest ~20% of items from the cache, either silently or with a one-line message? This would mean that, by default, you always have at least the last 800 outputs available.

Stefan van der Walt

That sounds like a much more reasonable approach to cache handling.

The reason I "fixed" the execution count is because the notebook relies on that number not becoming much more than 3 digits. But, then again, how many people ever run 10,000 lines of execution in IPython (a notebook like that would be really, really slow to execute in full).

Thomas Kluyver
Collaborator

OK, I'll have a go at reworking the cache handling.

Hmmm, what's the issue in the notebook if the number exceeds three digits? Is that something we can fix? But I agree, it's unlikely that a notebook will get that long. I think the notebook model also lends itself to fewer, longer, multiline cells, and we should only need one number per cell.

I'm going to close this PR and open a new issue for the cache handling.

Thomas Kluyver takluyver closed this August 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 19, 2011
Stefan van der Walt Reset execution counter after cache is cleared. 60799a1
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 0 deletions. Show diff stats Hide diff stats

  1. 2  IPython/core/displayhook.py
2  IPython/core/displayhook.py
@@ -327,3 +327,5 @@ def flush(self):
327 327
         # TODO: Is this really needed?
328 328
         gc.collect()
329 329
 
  330
+        self.shell.execution_count = 0
  331
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.