This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Queue.Empty issue - Python3.8
Type: crash Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Python_dev_IL, rhettinger, tim.peters
Priority: normal Keywords:

Created on 2020-03-28 18:51 by Python_dev_IL, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
FTP_Code_queue.py Python_dev_IL, 2020-03-28 18:51
Messages (6)
msg365225 - (view) Author: Guy Kogan (Python_dev_IL) Date: 2020-03-28 18:51
Python 3.8 Queue module is unable to handle the expection: 

error: 

Exception in thread Thread-5:
Traceback (most recent call last):
  File "FTP_multithreading.py", line 17, in run
    new_connection = self.queue.get(timeout=2)
  File "/usr/local/lib/python3.8/queue.py", line 178, in get
    raise Empty
_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "FTP_multithreading.py", line 18, in run
    except queue.Empty:
AttributeError: 'Queue' object has no attribute 'Empty'
b'220 ns.iren.ru FTP server (Version wu-2.6.2(1) Fri Sep 12 08:50:43 IRKST 2008) ready.\r\n'
Exception in thread Thread-4:
Traceback (most recent call last):
  File "FTP_multithreading.py", line 17, in run
    new_connection = self.queue.get(timeout=2)
  File "/usr/local/lib/python3.8/queue.py", line 178, in get
    raise Empty
_queue.Empty


When the Last task is done the exception queue.Empty should occur while handling the exception another exception is occurred.
msg365226 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-03-28 19:12
There's an error in your code:

    import queue          # loads the standard library queue module
    
    ...

    queue = queue.Queue() # reassign queue to an instance of Queue

    ...

    except queue.Empty:   # expects "queue" the module, not the instance
msg365229 - (view) Author: Guy Kogan (Python_dev_IL) Date: 2020-03-28 20:27
I still dont understand what do you mean? 

Can you please elaborate?
msg365230 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2020-03-28 20:35
Raymond is talking about the cause of this error in what you showed:

AttributeError: 'Queue' object has no attribute 'Empty'

The exception you're _trying_ to catch is "queue.Empty", where "queue" is the queue _module_.  But you rebound the name "queue" to an instance of the queue.Queue class.  As the AttributeError message says, an instance of that class has no "Empty" attribute.

You need to change this line:

  queue = queue.Queue()

Pick a different name, so the _intended_ "queue.Queue" still works.
msg365231 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2020-03-28 20:36
> ... so the _intended_ "queue.Queue" still works.

Oops.  Of course that should have said:

> ... so the _intended_ "queue.Empty" still works.
msg365233 - (view) Author: Guy Kogan (Python_dev_IL) Date: 2020-03-28 22:00
Thanks Tim Peters and Raymond Hettinger, the issue has been resolved.

Have a nice day!
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84278
2020-03-28 22:00:45Python_dev_ILsetstatus: open -> closed
resolution: works for me
messages: + msg365233

stage: resolved
2020-03-28 20:36:46tim.peterssetmessages: + msg365231
2020-03-28 20:35:34tim.peterssetnosy: + tim.peters
messages: + msg365230
2020-03-28 20:27:02Python_dev_ILsetmessages: + msg365229
2020-03-28 19:12:33rhettingersetnosy: + rhettinger
messages: + msg365226
2020-03-28 18:51:42Python_dev_ILcreate