Skip to content

Set calling program to UNKNOWN, when argv not in sys#3460

Merged
takluyver merged 1 commit intoipython:masterfrom
tomspur:no_sys_available
Jul 14, 2013
Merged

Set calling program to UNKNOWN, when argv not in sys#3460
takluyver merged 1 commit intoipython:masterfrom
tomspur:no_sys_available

Conversation

@tomspur
Copy link
Copy Markdown
Contributor

@tomspur tomspur commented Jun 24, 2013

It might happen, then the sys module has no argv, when embeding IPython
into other programs with IPython.embed(). In that case, just set the
calling program to UNKNOWN or other logic in IPython will crash - for
instance when checking for command line arguments.

@takluyver
Copy link
Copy Markdown
Member

Yuk, really? Under what conditions does this happen? The docs mention various special cases for argv, but not that it doesn't even exist.

@tomspur
Copy link
Copy Markdown
Contributor Author

tomspur commented Jun 24, 2013

It happend with https://github.com/psi4/psi4.0b4:

$ psi ipython-embed.py
Traceback (most recent call last):
  File "<string>", line 26, in <module>
  File "/home/tomspur/IPython.git/IPython/__init__.py", line 43, in <module>
    from .config.loader import Config
  File "/home/tomspur/IPython.git/IPython/config/__init__.py", line 16, in <module>
    from .application import *
  File "/home/tomspur/IPython.git/IPython/config/application.py", line 67, in <module>
    """.strip().format(app=os.path.basename(sys.argv[0]))
AttributeError: 'module' object has no attribute 'argv'

I never used boost-python so far, so I don't know why this can happen, but at least it does...

@takluyver
Copy link
Copy Markdown
Member

So it's embedding a Python interpreter, not just an IPython shell? I'm inclined to take the view that it's the embedding program's responsibility to provide a sane Python environment, not for us to work around any bizarre situation it can throw at us.

@tomspur
Copy link
Copy Markdown
Contributor Author

tomspur commented Jun 24, 2013

Yes, it's embedding a Python interpreter and I want to start ipython inside of it, so I have easier access to the internal structure of psi. I think this is a fairly easy workaround, which could happen in other programs too.

Nevertheless, it's your choice to include it or not, if the change is too nasty ;)

@takluyver
Copy link
Copy Markdown
Member

If this is something that programs embedding a Python interpreter often do, then I'd say we should accept it. If it's something peculiar to psi, then I'd rather leave it, because there are hundreds of ways you could mess up Python features that we rely on, and it's not our job to try to handle them.

@fperez
Copy link
Copy Markdown
Member

fperez commented Jun 28, 2013

@tomspur, thanks! This looks good, modulo that we'd much prefer to use '' (the empty string) instead of UNKNOWN. If you can make that change, we'll be happy to merge.

It might happen, then the sys module has no argv, when embeding IPython
into other programs with IPython.embed(). In that case, just set the
calling program to "" or other logic in IPython will crash - for
instance when checking for command line arguments.
@tomspur
Copy link
Copy Markdown
Contributor Author

tomspur commented Jul 1, 2013

@fperez, great, thanks. I've amended it to the empty string now instead.

@takluyver
Copy link
Copy Markdown
Member

LGTM, but I think the comment should explain why this is needed, not what it's doing.

@minrk
Copy link
Copy Markdown
Member

minrk commented Jul 8, 2013

Ready to merge, as soon as @tomspur updates the comment per @takluyver.

@takluyver
Copy link
Copy Markdown
Member

Finished off in #3632.

@tomspur tomspur deleted the no_sys_available branch July 17, 2013 13:04
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

Successfully merging this pull request may close these issues.

4 participants