--- /dev/null
+"""Robot based on aiohttp and concurrent.futures,
+processes multiple URLs in parallel (multithreaded).
+
+This file is a part of Bookmarks database and Internet robot.
+
+"""
+
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2024 PhiloSoft Design"
+__license__ = "GNU GPL"
+
+__all__ = ['robot_multiaio']
+
+
+import asyncio
+import aiohttp
+
+from Robots.bkmk_raio import _get_http, _get_ftp
+from Robots.concurrent_futures import cf_multithread
+
+
+class robot_multiaio(cf_multithread):
+ def __init__(self, *args, **kw):
+ self.async_pending = set() # pending async tasks
+ cf_multithread.__init__(self, *args, **kw)
+
+ def version_str(self):
+ return 'aiohttp/%s; multithreaded' % aiohttp.__version__
+
+ def main_thread(self):
+ asyncio.run(self.main_thread_async())
+
+ async def main_thread_async(self):
+ """Main loop"""
+
+ while True:
+ if self.queue.empty():
+ pass
+ else:
+ request = self.queue.get_nowait()
+ if request is None: # Signal to stop
+ return
+ url, req_headers, use_proxy, queue = request
+
+ task = asyncio.create_task(
+ self.get_url_task(url, req_headers, use_proxy, queue))
+ self.async_pending.add(task)
+
+ if self.async_pending:
+ done, async_pending = await asyncio.wait(
+ self.async_pending, timeout=self.timeout,
+ return_when=asyncio.FIRST_COMPLETED)
+ self.async_pending = async_pending
+
+ for task in done:
+ error, status, resp_headers, body, queue = task.result()
+ queue.put_nowait((error, status, resp_headers, body))
+
+ async def get_url_task(self, url, req_headers, use_proxy, queue):
+ if url.startswith('ftp://'):
+ error, body = await _get_ftp(
+ url, timeout=self.timeout,
+ )
+ if error is not None:
+ error = str(error)
+ return error, None, None, None, queue
+ return None, None, None, body, queue
+
+ if use_proxy:
+ proxy = self.proxy
+ else:
+ proxy = None
+
+ error, status, resp_headers, body = await _get_http(
+ url, req_headers, proxy=proxy,
+ timeout=self.timeout,
+ )
+ return error, status, resp_headers, body, queue
Version 6.2.0 (2024-??-??)
+ Robot based on aiohttp and concurrent.futures,
+ processes multiple URLs in parallel (multithreaded).
+ Works slowly, the same way as curl.
+
+ Default list of robots is multirequests,aio.
+
Robot based on twisted and concurrent.futures,
processes multiple URLs in parallel (multithreaded).
Doesn't properly support proxies; has problems with HTTP proxy
and doesn't support SOCKS5 proxy at all.
Doesn't query FTP; requires more work.
- Default list of robots is still multirequests,aio.
-
Robots: Removed ftp_timeout.
Version 6.2.0 (2024-??-??)
+ Robot based on aiohttp and concurrent.futures,
+ processes multiple URLs in parallel (multithreaded).
+ Works slowly, the same way as curl.
+
+ Default list of robots is multirequests,aio.
+
Robot based on twisted and concurrent.futures,
processes multiple URLs in parallel (multithreaded).
Doesn't properly support proxies; has problems with HTTP proxy
and doesn't support SOCKS5 proxy at all.
Doesn't query FTP; requires more work.
- Default list of robots is still multirequests,aio.
-
Robots: Removed ftp_timeout.
Version 6.1.0 (2024-09-08)