nemo 4.5.5 -> 4.6.3: python 3.9 asyncio circular dependency on library 'typing'

59 views
Skip to first unread message

Chris Price

unread,
Aug 25, 2023, 3:26:04 PM8/25/23
to nemo
Hi, during our upgrade from nemo 4.5.5 -> 4.6.3, we encountered a startup error.

It looks like python 3.9 asyncio imports "typing", and that finds NEMO/typing.py, which imports typing.

We worked around this by renaming NEMO/typing.py to NEMO/nemotyping.py, for now.

We can submit this upstream, but you may want to do this differently. Maybe we're not doing something you expect.

Here's the full stack:

Traceback (most recent call last):
 File "/home/oit-or-webapp-sa/.local/lib/python3.9/site-packages/NEMO/__init__.py", line 3, in <mod
ule>
   from django.apps import AppConfig
 File "/home/oit-or-webapp-sa/.local/lib/python3.9/site-packages/django/apps/__init__.py", line 1, 
in <module>
   from .config import AppConfig
 File "/home/oit-or-webapp-sa/.local/lib/python3.9/site-packages/django/apps/config.py", line 7, in
<module>
   from django.utils.deprecation import RemovedInDjango41Warning
 File "/home/oit-or-webapp-sa/.local/lib/python3.9/site-packages/django/utils/deprecation.py", line
1, in <module>
   import asyncio
 File "/usr/lib64/python3.9/asyncio/__init__.py", line 8, in <module>
   from .base_events import *
 File "/usr/lib64/python3.9/asyncio/base_events.py", line 45, in <module>
   from . import staggered
 File "/usr/lib64/python3.9/asyncio/staggered.py", line 6, in <module>
   import typing
 File "/data/pgmlib/nemo/nemo-mssql/NEMO/./typing.py", line 1, in <module>
   from typing import Generic, Iterator, TypeVar
ImportError: cannot import name 'Generic' from partially initialized module 'typing' (most likely du
e to a circular import) (/data/pgmlib/nemo/nemo-mssql/NEMO/./typing.py)
unable to load app 0 (mountpoint='') (callable not found or import error)

Let me know, thanks,
-Chris Price
UC Irvine


mathieu...@gmail.com

unread,
Aug 26, 2023, 12:32:29 PM8/26/23
to nemo, crp...@uci.edu
Hi Chris,
I tested using python 3.9.18 and I wasn't able to reproduce the error.
Could you try updating your version of python and try on a fresh virtual environment to see if it still happens?

Thanks,
Mathieu

Chris Price

unread,
Aug 28, 2023, 3:08:49 PM8/28/23
to nemo, mathieu...@gmail.com, Chris Price
Thanks for trying. Do you use a venv with system site packages enabled? We won't be able to upgrade to 3.9.18 anytime soon.

Mathieu Rampant

unread,
Aug 28, 2023, 4:59:13 PM8/28/23
to Chris Price, nemo
I also tried with 3.9.6 and didn't have any issues.
I tested locally (venv, system site packages enabled or not) and didn't have any issues.
I also tested it in a docker container, using the Dockerfile provided in NEMO and changing the python version (to 3.9.x)

What platform/operating system are you using?

Mat

Christopher Robert Price

unread,
Aug 28, 2023, 5:02:46 PM8/28/23
to Mathieu Rampant, nemo
Hmm, good to know. We're on RHEL8, we use venv with system site enabled. Maybe it's a RHEL packaging thing? I'm not sure at this point.

Mathieu Rampant

unread,
Aug 28, 2023, 5:23:43 PM8/28/23
to Christopher Robert Price, nemo
You can double check https://github.com/usnistgov/NEMO/blob/master/Dockerfile and https://github.com/usnistgov/NEMO/blob/master/start_NEMO_in_Docker.sh to make sure you are starting the server off properly.

In a nutshell:
  1. pip install NEMO==4.6.3 gunicorn==20.1.0
  2. gunicorn NEMO.wsgi:application (copy and use https://github.com/usnistgov/NEMO/blob/master/gunicorn_configuration.py if you want) 
You should not clone the repository or anything like that, just pip install and start

Mat

Christopher Robert Price

unread,
Sep 1, 2023, 3:39:07 PM9/1/23
to Mathieu Rampant, nemo
Hey Mat, thanks, we run it with customization. Our process does not follow the docker guidance.
This may make it difficult to demonstrate reproducibility for you.

We're working in Sept to upgrade python as per your suggestion.

Also, we're going to start working in Sept to suggest some of our customizations back to you (upstream).
We're hoping to discuss the features with you via that channel.
Of course you're welcome to reject. We're hoping to see also if there's a better way to do what we customized.

Also, props to your work on this project (and the previous development team(s)).
We went live August 14th here at UC Irvine, replacing our old system, and it's been great!

-Chris

--
You received this message because you are subscribed to the Google Groups "nemo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nemo+uns...@list.nist.gov.
To view this discussion on the web visit https://groups.google.com/a/list.nist.gov/d/msgid/nemo/CAGKmSFAinKV7GNaz1tU_eT%2BvyT_SQb8c5yBVaRix_KPx8%3DtKTg%40mail.gmail.com.

mathieu...@gmail.com

unread,
Sep 2, 2023, 10:33:41 AM9/2/23
to nemo, crp...@uci.edu, nemo, mathieu...@gmail.com
Hi Chris,
My (wild) guess is that maybe some configuration parameter or from your deployment of NEMO is putting NEMO's typing.py file at the top of the python path, essentially making the "import typing" look into NEMO's directory, rather than at the python library.

Congratulations on going live with NEMO!
I am happy to hear the transition went well, and thank you for letting us know, as we have no way of otherwise knowing who is actually using NEMO.

You are welcome to use this forum or Github discussions & issues to discuss your customizations.

I am looking forward to seeing what changes you made, and hopefully get approval to include them in the main NEMO.

Thanks,
Mat

mathieu...@gmail.com

unread,
Nov 4, 2023, 11:16:34 AM11/4/23
to nemo, mathieu...@gmail.com, crp...@uci.edu, nemo
Hi Chris,
I have an update on this issue.
I was able to reproduce it when setting the NEMO folder in the python path, which caused the dependency issue.

You should be able to fix your issue by setting the working directory (when using PyCharm) or the PYTHONPATH env variable to anything other than the NEMO folder.
When deploying, after installing NEMO you should delete the source folder.
When developing, in PyCharm or other IDE/environments, make sure to set the working directory to the parent NEMO folder, not the NEMO package.

Let me know if you are still having issues.

Thanks,
Mathieu

Christopher Robert Price

unread,
Nov 6, 2023, 2:48:23 PM11/6/23
to mathieu...@gmail.com, nemo
Wow, thank you for circling back with this information. We'll give it a shot. I appreciate your due diligence!
-Chris

Reply all
Reply to author
Forward
0 new messages