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

Fix deactivation of embedded instance. #10207

Merged
merged 1 commit into from
Jan 29, 2017
Merged

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Jan 27, 2017

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

@Carreau
Copy link
Member Author

Carreau commented Jan 29, 2017

@takluyver ? @minrk ?

else:
kill = True
if kill:
self.shell._disable_init_location()
Copy link
Member

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).

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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).

Copy link
Member Author

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
@Carreau
Copy link
Member Author

Carreau commented Jan 29, 2017

comments should be addressed (except the call-location/init-location thing where I don't think anything is needed)

@takluyver takluyver merged commit 83350fb into ipython:master Jan 29, 2017
@takluyver
Copy link
Member

Thanks!

@meeseeksdev backport to 5.x

lumberbot-app bot pushed a commit that referenced this pull request Jan 29, 2017
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
@Carreau Carreau deleted the fix-embedded branch January 29, 2017 22:12
Carreau added a commit that referenced this pull request Jan 29, 2017
@Carreau Carreau added the backported PR that have been backported by MrMeeseeks label Jan 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported PR that have been backported by MrMeeseeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants