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.

Author lukasz.langa
Recipients giampaolo.rodola, josiahcarlson, lukasz.langa
Date 2010-07-23.14:33:25
SpamBayes Score 2.5661182e-06
Marked as misclassified No
Message-id <1279895608.81.0.80539572871.issue9354@psf.upfronthosting.co.za>
In-reply-to
Content
Tested on Python 3.2a0 on Mac OS 10.6.4.

When you specify the most basic `file_dispatcher` and run the loop, `file_wrapper` fails because it doesn't provide the `getsockopt()` to fake being a socket.

The code
--------

import asyncore
import os

class FileDispatcher(asyncore.file_dispatcher):
    def handle_read(self):
        data = self.recv(8192)

fd = os.open('/etc/passwd', os.O_RDONLY)
s = FileDispatcher(fd)
os.close(fd)
asyncore.loop(timeout=0.01, use_poll=True, count=2)

Expected result
---------------
None, it should run OK silently.

Actual result
-------------
error: uncaptured python exception, closing channel <__main__.FileDispatcher at 0x100524e10> (<class 'AttributeError'>:'file_wrapper' object has no attribute 'getsockopt' [/opt/error-report/py3k/Lib/asyncore.py|readwrite|106] [/opt/error-report/py3k/Lib/asyncore.py|handle_write_event|449])
Traceback (most recent call last):
  File "/opt/error-report/py3k/Lib/asyncore.py", line 106, in readwrite
    obj.handle_write_event()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 449, in handle_write_event
    err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
AttributeError: 'file_wrapper' object has no attribute 'getsockopt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/error-report/error_report.py", line 11, in <module>
    asyncore.loop(timeout=0.01, use_poll=True, count=2)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 214, in loop
    poll_fun(timeout, map)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 195, in poll2
    readwrite(obj, flags)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 119, in readwrite
    obj.handle_error()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 489, in handle_error
    self.handle_close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 508, in handle_close
    self.close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 396, in close
    self.socket.close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 617, in close
    os.close(self.fd)
OSError: [Errno 9] Bad file descriptor

Patch
-----
Please find attached a patch that does add a unit test for this specific case and adds the most simple `getsockopt()` possible that is still reasonable. The patch was made with trunk r83090.
History
Date User Action Args
2010-07-23 14:33:28lukasz.langasetrecipients: + lukasz.langa, josiahcarlson, giampaolo.rodola
2010-07-23 14:33:28lukasz.langasetmessageid: <1279895608.81.0.80539572871.issue9354@psf.upfronthosting.co.za>
2010-07-23 14:33:26lukasz.langalinkissue9354 messages
2010-07-23 14:33:25lukasz.langacreate