Fix Windows compatibility: replace platform-specific num_fds() with runtime check
Arachnado crashes on Windows with AttributeError: 'Process' object has no attribute 'num_fds'. The psutil library provides num_fds() only on Unix/Linux/macOS, while Windows uses num_handles().
Changes
-
arachnado/process_stats.py: Replace direct
num_fds()call with runtime method detection usinghasattr()- Try
num_fds()first (Unix/Linux/macOS) - Fall back to
num_handles()(Windows) - Return
Noneif neither exists
- Try
- CHANGES.rst: Document the fix
Before/After
# Before - crashes on Windows
'num_fds': self.process.num_fds(),
# After - works cross-platform
num_fds = None
if hasattr(self.process, 'num_fds'):
num_fds = self.process.num_fds()
elif hasattr(self.process, 'num_handles'):
num_fds = self.process.num_handles()
'num_fds': num_fds,
Note: The second error in the issue (singledispatch/DeferredList.__mro__) is a Python 2.7 compatibility issue resolved in Python 3+.
Original prompt
This section details on the original issue you should resolve
<issue_title>Can't run arachnado </issue_title> <issue_description>I use annacoda27 for Windows 64-bit and my machine is Windows 10 pro.
When I type
arachnadoinCMDAnd this is an issue like that:
2017-03-10 11:57:28 [tornado.application] ERROR: Exception in callback <bound method ProcessStatsMonitor._emit of <arachnado.process_stats.ProcessStatsMonitor object at 0x00000000041854A8>>Traceback (most recent call last): File "c:\users\king\anaconda2\lib\site-packages\tornado\ioloop.py", line 1041, in _run return self.callback()File "c:\users\king\anaconda2\lib\site-packages\arachnado\process_stats.py", line 61, in _emit 'num_fds': self.process.num_fds(),AttributeError: 'Process' object has no attribute 'num_fds'This information refresh per second
When I stop arachnado some infomations come out
2017-03-10 11:57:33 [scrapy.crawler] INFO: Received SIGINT, shutting down gracefully. Send again to force2017-03-10 11:57:33 [tornado.application] ERROR: Exception in callback <functools.partial object at 0x0000000004247188>Traceback (most recent call last):Traceback (most recent call last):File "c:\users\king\anaconda2\lib\site-packages\tornado\ioloop.py", line 612, in _run_callback ret = gen.convert_yielded(ret)File "c:\users\king\anaconda2\lib\site-packages\singledispatch.py", line 210, in wrapper return dispatch(args[0].__class__)(*args, **kw)File "c:\users\king\anaconda2\lib\site-packages\singledispatch.py", line 191, in dispatch impl = _find_impl(cls, registry)File "c:\users\king\anaconda2\lib\site-packages\singledispatch.py", line 142, in _find_impl mro = _compose_mro(cls, registry.keys())File "c:\users\king\anaconda2\lib\site-packages\singledispatch.py", line 98, in _compose_mro bases = set(cls.__mro__)AttributeError: class DeferredList has no attribute '__mro__'I don't know what happend in the code.
Could you help me to point it out ?
Best wishes</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes TeamHG-Memex/arachnado#32
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.