-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix deactivation of embedded instance. #10207
Conversation
@takluyver ? @minrk ? |
else: | ||
kill = True | ||
if kill: | ||
self.shell._disable_init_location() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't you got these back to front? This is the instance
branch, but it looks like it's killing by location (and vice versa).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since you've added a distinction between call location and init location, do we need ways to kill by both? Or is that starting to get too arcane and fiddly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I see - setting shell.embedded_active = False
is equivalent to killing by call location, because of the property access. I'd forgotten about that bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's a bit weird, killing by instance by setting an attribute on the instance does not really help if instances are created in a loop. So I do keep track of instance location and call location.
Honestly I shouldn't have make the "embedded_active" a property and keep all these details private... but backward compatibility. The worst case I'm trying to cover is :
for loop:
ipembed = InteractiveShellEmbed()
if option:
ipembed()
elseif:
ipembed()
else:
ipembed()
You can either kill the 3 call locations or kill a single instance location.
I agree that the "instance location" is abit weirdish, but that's the behavior of 5.0 and 5.1, so I leave it as an option.
So I think I got the logic right, and I think we should keep both.
@@ -311,7 +379,8 @@ def embed(**kwargs): | |||
cls.clear_instance() | |||
frame = sys._getframe(1) | |||
shell = InteractiveShellEmbed.instance(_call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno), **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this line, I think _call_location_id
should be changed to _init_location_id
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed.
if self._call_location_id in InteractiveShellEmbed._inactive_locations: | ||
InteractiveShellEmbed._inactive_locations.remove(self._call_location_id) | ||
InteractiveShellEmbed._inactive_locations.remove( | ||
self._call_location_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, sets have a .discard()
method which is like .remove()
but doesn't raise if the item isn't in the set. So instead of checking if a in b: b.remove(a)
, we can just do b.discard(a)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ! Sweet ! Thanks !
While deactivation of full instances make some sens, the most common behavior user expect when creating an instance and using ``kill_embedded`` is deactivation of the current call location. Implement the expected on by default, add options to get previous behavior, and add flag for direct exit and no-confirm Fix ipython#9761
comments should be addressed (except the call-location/init-location thing where I don't think anything is needed) |
Thanks! @meeseeksdev backport to 5.x |
While deactivation of full instances make some sens, the most common behavior user expect when creating an instance and using ``kill_embedded`` is deactivation of the current call location. Implement the expected on by default, add options to get previous behavior, and add flag for direct exit and no-confirm Fix 9761
Backport PR #10207 on branch 5.x
While deactivation of full instances make some sens, the most common
behavior user expect when creating an instance and using
kill_embedded
is deactivation of the current call location.Implement the expected on by default, add options to get previous
behavior, and add flag for direct exit and no-confirm
Fix #9761