CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

Issue with Tensorflow Session #163

Closed ducva closed 7 years ago

ducva commented 7 years ago

I created sample project at

green_tensorflow_bug Repository

For now, I can't use green to run my unit test with Tensorflow.

Run test with green:

green test.py

$ green test.py
Before load graph
Before create session
After creating session

<STUCK HERE>

Run test with python

python test.py

$ python test.py
Before load graph
Before create session
After creating session
Test data: [[ 0.   0.5  0.   0.   0.   0.   0.   0.   2.   0.   0.   0.   0. ]]
Prepare to run Tensorflow Session
Finish run Tensorflow session
.
----------------------------------------------------------------------
Ran 1 test in 0.012s

OK

Please help!

CleanCut commented 7 years ago

TL;DR Problem caused by module running code on import that doesn't play well with multiple instances of itself running. Suggested fix in PR here to not run that code at import time.

MinchinWeb commented 7 years ago

When I first saw this, I wondered if it was something with threads. Does running green on a single thread fix this?

green -s 1 test.py
CleanCut commented 7 years ago

@MinchinWeb No, because that only means a single worker process. You still have the main process that imports all the libraries to decide how they should be distributed to workers, and since the bug was caused by run-at-import issues, the import in the main process and the import of any worker process (including just a single one) would collide.

There are other classes of behavior problems that can be avoided by just using a single worker process, but not this particular one.

MinchinWeb commented 7 years ago

@CleanCut Thanks for the explanation!

CleanCut commented 7 years ago

Any time. 😎