vxgmichel/aioconsole

bug: automatically import any `queue.py` from the same directory.

rendarz opened this issue · 2 comments

Hello, I have just discovered an aioconsole bug:
If I run a program which imports aioconsole, and in the same directory of that program there will be a file called queue.py, that
file, whatever it contains, it will be imported too, causing A LOT of bugs.
I've spent 2 hrs to figure out that the strange behavior I was getting was due to this.

I will share a screenshot to show you a simple snippet of this unwanted behavior.

NOTE: In the screenshot, py is just an alias for python which I use in my shell.

Thank you for your time.
Screenshot_2021-08-24_10-38-24

Hi @rendarz and thanks for the report!

It turns out you just ran into the name shadowing trap. You can replace the content of prompt.py with:

from concurrent.futures import ThreadPoolExecutor
ThreadPoolExecutor()

and note that the problem still occurs. Also, the following trace is produced:

Traceback (most recent call last):
  File "/home/vinmic/repos/test.py", line 3, in <module>
    ThreadPoolExecutor()
  File "/home/vinmic/miniconda/lib/python3.9/concurrent/futures/thread.py", line 144, in __init__
    self._work_queue = queue.SimpleQueue()
AttributeError: module 'queue' has no attribute 'SimpleQueue'

.. making it more obvious that the standard library module queue has been shadowed. The solution is simply to not have a local module module with the same name as a standard library module.

Since it's unrelated to aioconsole I'm closing the issue :)

Thanks for your help, that's clear now. :)