python是否会受到循环依赖问题的影响?

时间:2013-10-11 14:53:45

标签: python

我得到了这个堆栈跟踪:

  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/flow_conditions.py", line 3, in <module>
    from gitflow.flow_config import ConfigManager
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/flow_config.py", line 19, in <module>
    from gitflow.flow_workflow import FlowCommand, WorkflowCommand
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/flow_workflow.py", line 5, in <module>
    from gitflow.flow_conditions import ConditionFactory
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/flow_conditions.py", line 3, in <module>
    from gitflow.flow_config import ConfigManager
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/flow_config.py", line 19, in <module>
    from gitflow.flow_workflow import FlowCommand, WorkflowCommand
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/flow_workflow.py", line 5, in <module>
    from gitflow.flow_conditions import ConditionFactory
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/flow_conditions.py", line 3, in <module>
    from gitflow.flow_config import ConfigManager
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/flow_config.py", line 19, in <module>
    from gitflow.flow_workflow import FlowCommand, WorkflowCommand
  File "/usr/lib/python2.7/site-packages/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/gitflow/flow_workflow.py", line 5, in <module>
    from gitflow.flow_conditions import ConditionFactory
  File "/usr/lib/python2.7/site-packages/gitflow/flow_conditions.py", line 3, in <module>

我找不到我的代码有什么问题,这让我觉得我不确定是Python中的问题。循环依赖。 python是否能很好地处理循环依赖,或者我应该重构它们以确定是否能解决问题。

感谢。

1 个答案:

答案 0 :(得分:4)

如果你有这个:

# in foo.py
from bar import cat

# in bar.py
from foo import dog

这会创建两个模块的无限循环,试图互相导入。 Python特别不能处理这个问题,因为人们普遍认为循环依赖是不良设计的标志。