__import__ fails randomly due to missing file

Arkadiusz Bulski arek.bulski at gmail.com
Mon Mar 12 05:12:15 EDT 2018


Hi,

For the record, I am the developer of Construct library. And the question
relates to it.
https://construct.readthedocs.io/en/latest/#

I have an issue of Travis failing randomly at test cases. The cause is
always __import__ failing to import a dynamically generated code. Library
generates a string, saves it to a file (closes the file too), then
__import__ it. I dont think there is anything wrong with the (generated
imported) code itself. It seems like its some sort of issue with the Python
runtime (or filesystem) not detecting the file because it was created only
a moment ago. I tried to solve it by adding os.sync() between writing the
file and importing it, but it seems to have only decreased the error rate,
not solved it. Frankly, this is a heisenbug. Re-running the Travis job
usually fixes it. Its random and happens very rarely. I havent pinpointed
it to any particular version of CPython or Pypy (although I dont remember
it ever happening on Pypy).

An example:
https://travis-ci.org/construct/construct/jobs/352213556

The code in question:
https://github.com/construct/construct/blob/d9c645ed0a75b5a2b64318113cf69cac822fd8f5/construct/core.py#L402-L414
https://github.com/construct/construct/blob/d9c645ed0a75b5a2b64318113cf69cac822fd8f5/construct/core.py#L179-L180

-- 
~ Arkadiusz Bulski
~ tel 503 357 111 lub WhatsApp/Telegram



More information about the Python-list mailing list