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

Utility functions located in wrong place #2128

Open
styxx3542 opened this issue Mar 9, 2023 · 8 comments
Open

Utility functions located in wrong place #2128

styxx3542 opened this issue Mar 9, 2023 · 8 comments

Comments

@styxx3542
Copy link

styxx3542 commented Mar 9, 2023

There seems to be a config error when one tries to import multiple modules from Ganga.
#Steps to reproduce

  1. Make a new file
  2. Write the code as mentioned below.

import ganga.ganga
from ganga.GangaTest.Framework.utils import sleep_until_completed

#Reason
The reasoning that seemed reasonable was that ganga is engaging bootloaders when we import it for the first time. So, when we use a second import, it throws a config error

@egede
Copy link
Member

egede commented Mar 9, 2023

Please include code as text (not image) as well and boil the example down to the absolute minimal. The problem comes already from line 2, so presumably everything below there is irrelevant. Also you can probably reduce the number of imports in line 2, to the minimal tha t will still show the failure.

@styxx3542
Copy link
Author

Understood. I'll edit it to make sure it's compliant.

@egede
Copy link
Member

egede commented Mar 9, 2023

Here with the error included. Why we get the identical INFO message written 5 times is also odd.

In [1]: import ganga.ganga
INFO     reading config file /home/egede/.gangarc
INFO     reading config file /home/egede/.gangarc
INFO     reading config file /home/egede/.gangarc
INFO     reading config file /home/egede/.gangarc
INFO     reading config file /home/egede/.gangarc

In [2]: from ganga.GangaTest.Framework.utils import sleep_until_completed
---------------------------------------------------------------------------
ConfigError                               Traceback (most recent call last)
Input In [2], in <module>
----> 1 from ganga.GangaTest.Framework.utils import sleep_until_completed

File ~/programming/ganga/ganga/ganga/GangaTest/Framework/__init__.py:1, in <module>
----> 1 import GangaTest.Framework.runner

File ~/programming/ganga/ganga/ganga/GangaTest/Framework/__init__.py:1, in <module>
----> 1 import GangaTest.Framework.runner

File ~/programming/ganga/ganga/ganga/GangaTest/Framework/runner.py:42, in <module>
     39 gangaReleaseTopDir = previous_dir(myFullPath, 3)
     41 # testing framework configuration properties
---> 42 myConfig = makeConfig('TestingFramework', 'Configuration section for internal testing framework')
     44 # Release testing mode:
     45 # - xml/html reports are generated
     46 # - coverage analysis tool enabled
     47 myConfig.addOption('ReleaseTesting', False, '')

File ~/programming/ganga/ganga/ganga/GangaCore/Utility/Config/Config.py:188, in makeConfig(name, docstring, **kwds)
    183 """
    184 Create a config package and attach metadata to it. makeConfig() should be called once for each package.
    185 """
    187 if _after_bootstrap:
--> 188     raise ConfigError('attempt to create a configuration section [%s] after bootstrap' % name)
    190 try:
    191     c = allConfigs[name]

ConfigError: ConfigError: attempt to create a configuration section [TestingFramework] after bootstrap 

@egede
Copy link
Member

egede commented Mar 9, 2023

We obviously execute the line

GangaCore/Utility/Config/Config.py:        logger.info('reading config file %s', f)

five times during the bootstrap. Seems like an overkill.

The best way of dealing with the bug here might just be to allow the configuration to be updated after bootstrap. What harm would it do?

@alexanderrichards
Copy link
Contributor

alexanderrichards commented Mar 10, 2023

five times during the bootstrap. Seems like an overkill.

I would say this is a bug rather than overkill. It's been a long time since I worked on this code in anger but I recall that it only read this file once and then would read another file if for example you specified a different config.

We should figure out why it's being read 5 times. I will see if I get the same behaviour.


edit: I've just realised that this is from importing ganga with in an interactive session rather than starting gange standalone. I was referring to ganga standalone. In any case I would expect the behaviour to be the same so we should figure out what the difference is

@mesmith75
Copy link
Contributor

The best way of dealing with the bug here might just be to allow the configuration to be updated after bootstrap. What harm would it do?

I think one needs to be careful - we set up the config with a priority depending on where options are specified, i.e. SessionValue, UserValue - this may upset the order and cause unexpected behaviour

@egede
Copy link
Member

egede commented Mar 13, 2023

The issue of the repeated reading of the .gangarc file has been assigned a separate issue #2129

@egede egede changed the title Config Error while importing modules from ganga Config Error when importing package from unloaded plugin Mar 13, 2023
@egede
Copy link
Member

egede commented Mar 13, 2023

The issue

In [1]: import ganga.ganga
In [2]: from ganga.GangaTest.Framework.utils import sleep_until_completed
---------------------------------------------------------------------------
ConfigError                               Traceback (most recent call last)

is not a bug as such. The config system is static in structure after the import of Ganga in [1]. However, error message should be improved (should be a GangaError of ERROR or CRITICAL).

A way to solve the specific problem here is actually to move the utility function sleep_until_completed and friends to the GangaCore package. The real problem is caused by the init.py file in the folder.

@egede egede changed the title Config Error when importing package from unloaded plugin Utility functions located in wrong place Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants