Python 运行时错误:populate()不是';t重入导入循环

Python 运行时错误:populate()不是';t重入导入循环,python,django,Python,Django,我让models.py文件导入一个外部函数,然后将其写入特定的模型。我认为这是某种导入循环,但我不确定 这是部分回溯 File "path/Directory/Package/models.py", line 19, in <module> from externalFunction import myFunction File "path/Directory/externalFunction.py", line 9, in <

我让models.py文件导入一个外部函数,然后将其写入特定的模型。我认为这是某种导入循环,但我不确定

这是部分回溯

File "path/Directory/Package/models.py", line 19, in <module>
    from externalFunction import myFunction
  File "path/Directory/externalFunction.py", line 9, in <module>
    django.setup()
  File "/path/anaconda3/envs/myEnv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/path/anaconda3/envs/Brew/lib/python3.6/site-packages/django/apps/registry.py", line 83, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant

models.py

from django.db import models
import sys
sys.path.append("..")
from externalFunction import myFunction

class Job(models.Model):
    name = models.CharField(
        max_length=30,
        default="name")
@receiver(post_save, sender=Job, dispatch_uid="run function")
def run_function(sender, instance, created, *args, **kwargs):
    someOtherFunction()
    myFunction()
import django
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Package_api.settings')
django.setup()
from Package.models import Job

def myFunction():
    some stuff
externalFunction.py

from django.db import models
import sys
sys.path.append("..")
from externalFunction import myFunction

class Job(models.Model):
    name = models.CharField(
        max_length=30,
        default="name")
@receiver(post_save, sender=Job, dispatch_uid="run function")
def run_function(sender, instance, created, *args, **kwargs):
    someOtherFunction()
    myFunction()
import django
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Package_api.settings')
django.setup()
from Package.models import Job

def myFunction():
    some stuff
我已尝试从externalFunction.py中删除
django.setup()
,但它无法从模型中导入作业