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 Carreau commented Jan 29, 2017

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

@takluyver takluyver Jan 29, 2017

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

@takluyver takluyver Jan 29, 2017

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

@takluyver takluyver Jan 29, 2017

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

@Carreau Carreau Jan 29, 2017

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

@takluyver takluyver Jan 29, 2017

On this line, I think _call_location_id should be changed to _init_location_id, right?

Copy link
Member Author

@Carreau Carreau Jan 29, 2017

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

@takluyver takluyver Jan 29, 2017

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

@Carreau Carreau Jan 29, 2017

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 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
4 checks passed
@takluyver
Copy link
Member

@takluyver takluyver commented Jan 29, 2017

Thanks!

@meeseeksdev backport to 5.x

meeseeksdev bot pushed a commit that referenced this issue 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 Jan 29, 2017
Carreau added a commit that referenced this issue Jan 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants