HewlettPackard / python-hpOneView

DEPRECATED - no longer actively maintained. New repository: https://github.com/HewlettPackard/oneview-python
MIT License
87 stars 57 forks source link

Program running twice when importing hpOneView #177

Closed andrefaranha closed 8 years ago

andrefaranha commented 8 years ago

We are facing a weird problem when using python-hpOneView. All statements are running twice after adding the import.

Example:

Before importing:

print 'hello'

Output:

$ python test.py 
hello

After importing:

from hpOneView.oneview_client import OneViewClient

print 'hello'

Expected Output:

$ python test.py 
hello

Actual Output:

$ python test.py 
hello
hello

UPDATE:

It worked as expected after adding if __name__ == '__main__':

from hpOneView.oneview_client import OneViewClient

if __name__ == '__main__':
    print 'hello'

Output:

$ python test.py 
hello
marikrg commented 8 years ago

Which python version and operating system are you using?

marikrg commented 8 years ago

@andrefaranha I could reproduce the issue, thank you for reporting it.

andrefaranha commented 8 years ago

Sorry for the late response. I'm using python 2.7.12

marikrg commented 8 years ago

After some research I realised that it is not a bug on the SDK, it happens after enabling the support for renamed standard library modules using the future library.

Basically, the same behaviour occurs replacing the import:

from hpOneView.oneview_client import OneViewClient

by the following lines:

from future import standard_library
standard_library.install_aliases()

There is an internal module on Python named test, that is being imported when the install_aliases is called. You can check the code at: https://github.com/PythonCharmers/python-future/blob/master/src/future/standard_library/__init__.py#L483

I suggest renaming your module from test to something else, to avoid the conflict with the Python's internal module.

tiagomtotti commented 8 years ago

@andrefaranha have you seen @marikrg comment about this Issue ? Did it solve your problem ?

tiagomtotti commented 8 years ago

@andrefaranha since we didn't have a response, I'll close the issue. If you find that this problem still happens after applying the steps suggested by @marikrg, please reopen this issue.