You can implement thread pools by adding a single line of code without changing the order of any previous code.
===============================================================================================================
.. code-block:: python
import vthread
@vthread.pool(3) # just use this line to make pool, Create a threadpool with three threads
def crawl(i):
import time;time.sleep(1) # Simulation time consuming
print("crawl_url:",i)
urls = ["http://url1",
"http://url2",
"http://url3",
"http://url4"]
for u in urls:
crawl(u) # This function becomes a function that adds the original function to the thread pool.
It provides a method for grouping the thread pool
=================================================
.. code-block:: python
import vthread
pool_1 = vthread.pool(5,gqueue=1) # open a threadpool with 5 threads named 1
pool_2 = vthread.pool(2,gqueue=2) # open a threadpool with 2 threads named 2
@pool_1
def foolfunc1(num):
time.sleep(1)
print(f"foolstring1, test3 foolnumb1:{num}")
@pool_2
def foolfunc2(num):
time.sleep(1)
print(f"foolstring2, test3 foolnumb2:{num}")
@pool_2
def foolfunc3(num):
time.sleep(1)
print(f"foolstring3, test3 foolnumb3:{num}")
for i in range(10): foolfunc1(i)
for i in range(4): foolfunc2(i)
for i in range(2): foolfunc3(i)
# default gqueue is 0
Raw data
{
"_id": null,
"home_page": "https://github.com/cilame/vthread",
"name": "vthread",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "vilame",
"author_email": "opaquism@hotmail.com",
"download_url": "",
"platform": "",
"description": "\nYou can implement thread pools by adding a single line of code without changing the order of any previous code.\n===============================================================================================================\n\n.. code-block:: python\n\n import vthread\n \n @vthread.pool(3) # just use this line to make pool, Create a threadpool with three threads\n def crawl(i):\n import time;time.sleep(1) # Simulation time consuming\n print(\"crawl_url:\",i)\n \n urls = [\"http://url1\",\n \"http://url2\",\n \"http://url3\",\n \"http://url4\"]\n \n for u in urls:\n crawl(u) # This function becomes a function that adds the original function to the thread pool.\n\n\nIt provides a method for grouping the thread pool\n=================================================\n\n.. code-block:: python\n\n import vthread\n pool_1 = vthread.pool(5,gqueue=1) # open a threadpool with 5 threads named 1\n pool_2 = vthread.pool(2,gqueue=2) # open a threadpool with 2 threads named 2\n \n @pool_1\n def foolfunc1(num):\n time.sleep(1)\n print(f\"foolstring1, test3 foolnumb1:{num}\")\n \n @pool_2 \n def foolfunc2(num):\n time.sleep(1)\n print(f\"foolstring2, test3 foolnumb2:{num}\")\n\n @pool_2 \n def foolfunc3(num):\n time.sleep(1)\n print(f\"foolstring3, test3 foolnumb3:{num}\")\n \n for i in range(10): foolfunc1(i)\n for i in range(4): foolfunc2(i) \n for i in range(2): foolfunc3(i)\n # default gqueue is 0\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "the best threadpool pack.",
"version": "0.1.5",
"project_urls": {
"Homepage": "https://github.com/cilame/vthread"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "977b3d3944cc5de9e443253b860ecdfcee8098ca6afded234cf28df363f1bbb3",
"md5": "500a677c3ef978f1caf4522d6feff119",
"sha256": "0b9a7101170a51c5c5d9d2b287367a52821c4f22ab701a184591b7dab84c9b0b"
},
"downloads": -1,
"filename": "vthread-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "500a677c3ef978f1caf4522d6feff119",
"packagetype": "bdist_wheel",
"python_version": "3.7",
"requires_python": null,
"size": 14164,
"upload_time": "2022-01-13T03:49:12",
"upload_time_iso_8601": "2022-01-13T03:49:12.917408Z",
"url": "https://files.pythonhosted.org/packages/97/7b/3d3944cc5de9e443253b860ecdfcee8098ca6afded234cf28df363f1bbb3/vthread-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-01-13 03:49:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cilame",
"github_project": "vthread",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "vthread"
}