Compare commits

...

8 Commits
v2.11.0 ... dev

Author SHA1 Message Date
Andy Pan
a0e137a51c chore: add a new use case 2025-09-27 16:40:56 +08:00
Andy Pan
49d5ce6567 chore: update READMEs 2025-08-08 22:38:10 +08:00
Andy Pan
d12e26cb9e docs: add more use cases 2025-07-31 20:26:27 +08:00
Andy Pan
0de04f1c99
docs: update the comment on Options.PanicHandler to match its behavior (#365)
Fixes #364
2025-04-12 18:21:18 +08:00
POABOB
a44594205e
bug: don't reset the worker queue when rebooting preallocated pool (#360)
Fixes #358
2025-03-07 23:11:10 +08:00
Andy Pan
1bf9cfdd1b chore: bump up modules 2025-02-09 18:25:51 +08:00
Andy Pan
6eb0590bc2 chore: update READMEs 2025-01-17 20:11:32 +08:00
Andy Pan
3120dab1dd ci: fix the deprecated argument of codecov 2025-01-12 23:47:01 +08:00
9 changed files with 157 additions and 55 deletions

View File

@ -91,8 +91,8 @@ body:
- type: textarea
id: code
attributes:
label: Code snippets (optional)
description: Helpful code snippets can really speed up the process of locating root cause and fixing the bug.
label: Reproducer
description: Please provide the minimal code to reproduce the bug.
render: go
- type: textarea
id: how-to-reproduce

View File

@ -89,7 +89,7 @@ jobs:
- name: Upload code coverage report to Codecov
uses: codecov/codecov-action@v5
with:
file: ./codecov.report
files: ./codecov.report
flags: unittests
name: codecov-ants
fail_ci_if_error: true

View File

@ -147,7 +147,7 @@ The source code in `ants` is available under the [MIT License](/LICENSE).
## 🖥 Use cases
### business corporations
### business corporations & open-source organizations
Trusted by the following corporations/organizations.
@ -160,7 +160,7 @@ Trusted by the following corporations/organizations.
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.bytedance.com/en/" target="_blank">
<a href="https://www.bytedance.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/ByteDance_Logo.png" width="250" />
</a>
</td>
@ -258,7 +258,19 @@ Trusted by the following corporations/organizations.
<img src="https://res.strikefreedom.top/static_res/logos/amap-logo.png" width="250" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.apache.org/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/asf-estd-1999-logo.jpg" width="250" />
</a>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<a href="https://www.coze.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/coze-logo.png" width="250" />
</a>
</td>
</tr>
</tbody>
</table>
@ -273,6 +285,9 @@ The open-source projects below do concurrent programming with the help of `ants`
- [nps](https://github.com/ehang-io/nps): A lightweight, high-performance, powerful intranet penetration proxy server, with a powerful web management terminal.
- [TDengine](https://github.com/taosdata/TDengine): TDengine is an open source, high-performance, cloud native time-series database optimized for Internet of Things (IoT), Connected Cars, and Industrial IoT.
- [siyuan](https://github.com/siyuan-note/siyuan): SiYuan is a local-first personal knowledge management system that supports complete offline use, as well as end-to-end encrypted synchronization.
- [BillionMail](https://github.com/aaPanel/BillionMail): A future open-source Mail server, Email marketing platform designed to help businesses and individuals manage their email campaigns with ease.
- [WeKnora](https://github.com/Tencent/WeKnora): An LLM-powered framework designed for deep document understanding and semantic retrieval, especially for handling complex, heterogeneous documents.
- [coze-loop](https://github.com/coze-dev/coze-loop): A developer-oriented, platform-level solution focused on the development and operation of AI agents.
- [osmedeus](https://github.com/j3ssie/osmedeus): A Workflow Engine for Offensive Security.
- [jitsu](https://github.com/jitsucom/jitsu/tree/master): An open-source Segment alternative. Fully-scriptable data ingestion engine for modern data teams. Set-up a real-time data pipeline in minutes, not days.
- [triangula](https://github.com/RH12503/triangula): Generate high-quality triangulated and polygonal art from images.
@ -304,25 +319,31 @@ If you have `ants` integrated into projects, feel free to open a pull request re
<a href="https://www.jetbrains.com/?from=ants" target="_blank"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg" alt="JetBrains logo."></a>
## 💰 Backers
Support us with a monthly donation and help us continue our activities.
<a href="https://opencollective.com/ants#backers" target="_blank"><img src="https://opencollective.com/ants/backers.svg"></a>
## 💎 Sponsors
Become a bronze sponsor with a monthly donation of $10 and get your logo on our README on GitHub.
<a href="https://opencollective.com/ants#sponsors" target="_blank"><img src="https://opencollective.com/ants/sponsors.svg"></a>
## ☕️ Buy me a coffee
> Please be sure to leave your name, GitHub account, or other social media accounts when you donate by the following means so that I can add it to the list of donors as a token of my appreciation.
<img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/WeChatPay.JPG" width="250" align="middle"/>&nbsp;&nbsp;
<img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/AliPay.JPG" width="250" align="middle"/>&nbsp;&nbsp;
<a href="https://www.paypal.me/R136a1X" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/PayPal.JPG" width="250" align="middle"/></a>&nbsp;&nbsp;
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a target="_blank" href="https://buymeacoffee.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/bmc_qr.png" width="250" alt="By me coffee" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://www.patreon.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/patreon_logo.png" width="250" alt="Patreon" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://opencollective.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/open-collective-logo.png" width="250" alt="OpenCollective" />
</a>
</td>
</tr>
</tbody>
</table>
## 🔋 Sponsorship

View File

@ -148,7 +148,7 @@ pool.Reboot()
## 🖥 用户案例
### 商业公司
### 商业公司和开源组织
以下公司/组织在生产环境上使用了 `ants`
@ -161,7 +161,7 @@ pool.Reboot()
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.bytedance.com/" target="_blank">
<a href="https://www.bytedance.com/zh/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/ByteDance_Logo.png" width="250" />
</a>
</td>
@ -258,10 +258,21 @@ pool.Reboot()
<img src="https://res.strikefreedom.top/static_res/logos/amap-logo.png" width="250" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.apache.org/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/asf-estd-1999-logo.jpg" width="250" />
</a>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<a href="https://www.coze.cn/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/coze-logo-cn.png" width="250" />
</a>
</td>
</tr>
</tbody>
</table>
如果你也正在生产环境上使用 `ants`,欢迎提 PR 来丰富这份列表。
### 开源软件
@ -273,6 +284,9 @@ pool.Reboot()
- [nps](https://github.com/ehang-io/nps): 一款轻量级、高性能、功能强大的内网穿透代理服务器。
- [TDengine](https://github.com/taosdata/TDengine): TDengine 是一款开源、高性能、云原生的时序数据库 (Time-Series Database, TSDB)。TDengine 能被广泛运用于物联网、工业互联网、车联网、IT 运维、金融等领域。
- [siyuan](https://github.com/siyuan-note/siyuan): 思源笔记是一款本地优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。
- [BillionMail](https://github.com/aaPanel/BillionMail): BillionMail 是一个未来的开源邮件服务器和电子邮件营销平台,旨在帮助企业和个人轻松管理他们的电子邮件营销活动。
- [WeKnora](https://github.com/Tencent/WeKnora): 一款基于大语言模型LLM的文档理解与语义检索框架专为结构复杂、内容异构的文档场景而打造。
- [coze-loop](https://github.com/coze-dev/coze-loop): Coze Loop 是一个面向开发者,专注于 AI Agent 开发与运维的平台级解决方案。
- [osmedeus](https://github.com/j3ssie/osmedeus): A Workflow Engine for Offensive Security.
- [jitsu](https://github.com/jitsucom/jitsu/tree/master): An open-source Segment alternative. Fully-scriptable data ingestion engine for modern data teams. Set-up a real-time data pipeline in minutes, not days.
- [triangula](https://github.com/RH12503/triangula): Generate high-quality triangulated and polygonal art from images.
@ -304,25 +318,31 @@ pool.Reboot()
<a href="https://www.jetbrains.com/?from=ants" target="_blank"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg" alt="JetBrains logo."></a>
## 💰 支持
如果有意向,可以通过每个月定量的少许捐赠来支持这个项目。
<a href="https://opencollective.com/ants#backers" target="_blank"><img src="https://opencollective.com/ants/backers.svg"></a>
## 💎 赞助
每月定量捐赠 10 刀即可成为本项目的赞助者,届时您的 logo 或者 link 可以展示在本项目的 README 上。
<a href="https://opencollective.com/ants#sponsors" target="_blank"><img src="https://opencollective.com/ants/sponsors.svg"></a>
## ☕️ 打赏
> 当您通过以下方式进行捐赠时请务必留下姓名、GitHub 账号或其他社交媒体账号,以便我将其添加到捐赠者名单中,以表谢意。
<img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/WeChatPay.JPG" width="250" align="middle"/>&nbsp;&nbsp;
<img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/AliPay.JPG" width="250" align="middle"/>&nbsp;&nbsp;
<a href="https://www.paypal.me/R136a1X" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/payments/PayPal.JPG" width="250" align="middle"/></a>&nbsp;&nbsp;
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a target="_blank" href="https://buymeacoffee.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/bmc_qr.png" width="250" alt="By me coffee" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://www.patreon.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/patreon_logo.png" width="250" alt="Patreon" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://opencollective.com/panjf2000">
<img src="https://res.strikefreedom.top/static_res/logos/open-collective-logo.png" width="250" alt="OpenCollective" />
</a>
</td>
</tr>
</tbody>
</table>
## 🔋 赞助商

View File

@ -1535,3 +1535,71 @@ func TestMultiPoolWithFuncGeneric(t *testing.T) {
mp.Tune(10)
}
func TestRebootNewPoolCalc(t *testing.T) {
atomic.StoreInt32(&sum, 0)
runTimes := 1000
wg.Add(runTimes)
pool, err := ants.NewPool(10)
require.NoError(t, err)
defer pool.Release()
// Use the default pool.
for i := 0; i < runTimes; i++ {
j := i
_ = pool.Submit(func() {
incSumInt(int32(j))
})
}
wg.Wait()
require.EqualValues(t, 499500, sum, "The result should be 499500")
atomic.StoreInt32(&sum, 0)
wg.Add(runTimes)
err = pool.ReleaseTimeout(time.Second) // use both Release and ReleaseTimeout will occur panic
require.NoError(t, err)
pool.Reboot()
for i := 0; i < runTimes; i++ {
j := i
_ = pool.Submit(func() {
incSumInt(int32(j))
})
}
wg.Wait()
require.EqualValues(t, 499500, sum, "The result should be 499500")
}
func TestRebootNewPoolWithPreAllocCalc(t *testing.T) {
atomic.StoreInt32(&sum, 0)
runTimes := 1000
wg.Add(runTimes)
pool, err := ants.NewPool(10, ants.WithPreAlloc(true))
require.NoError(t, err)
defer pool.Release()
// Use the default pool.
for i := 0; i < runTimes; i++ {
j := i
_ = pool.Submit(func() {
incSumInt(int32(j))
})
}
wg.Wait()
require.EqualValues(t, 499500, sum, "The result should be 499500")
atomic.StoreInt32(&sum, 0)
err = pool.ReleaseTimeout(time.Second)
require.NoError(t, err)
pool.Reboot()
wg.Add(runTimes)
for i := 0; i < runTimes; i++ {
j := i
_ = pool.Submit(func() {
incSumInt(int32(j))
})
}
wg.Wait()
require.EqualValues(t, 499500, sum, "The result should be 499500")
}

4
go.mod
View File

@ -3,8 +3,8 @@ module github.com/panjf2000/ants/v2
go 1.18
require (
github.com/stretchr/testify v1.8.2
golang.org/x/sync v0.3.0
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.11.0
)
require (

15
go.sum
View File

@ -1,19 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -55,7 +55,9 @@ type Options struct {
Nonblocking bool
// PanicHandler is used to handle panics from each worker goroutine.
// if nil, panics will be thrown out again from worker goroutines.
// If nil, the default behavior is to capture the value given to panic
// and resume normal execution and print that value along with the
// stack trace of the goroutine
PanicHandler func(any)
// Logger is the customized logger for logging info, if it is not set,
@ -66,7 +68,7 @@ type Options struct {
DisablePurge bool
}
// WithOptions accepts the whole options config.
// WithOptions accepts the whole Options config.
func WithOptions(options Options) Option {
return func(opts *Options) {
*opts = options

View File

@ -170,8 +170,6 @@ retry:
w.finish()
goto retry
}
wq.items = wq.items[:0]
wq.size = 0
wq.head = 0
wq.tail = 0
}