Skip to content

Commit b660d36

Browse files
authored
add asyncio example
1 parent 9288f31 commit b660d36

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,28 @@ Except TimeoutException as e:
232232
print(e)
233233
```
234234

235+
### Async calls
236+
You can also make async calls with [asyncio], for example:
237+
238+
```
239+
import asyncio
240+
import concurrent.futures
241+
from twocaptcha import TwoCaptcha
242+
243+
captcha_result = await captchaSolver(image)
244+
245+
async def captchaSolver(image):
246+
loop = asyncio.get_running_loop()
247+
with concurrent.futures.ThreadPoolExecutor() as pool:
248+
result = await loop.run_in_executor(pool, lambda: TwoCaptcha(API_KEY).normal(image))
249+
return result
250+
```
251+
252+
235253
[2Captcha]: https://2captcha.com/
236254
[2captcha sofware catalog]: https://2captcha.com/software
237255
[pingback settings]: https://2captcha.com/setting/pingback
238256
[post options]: https://2captcha.com/2captcha-api#normal_post
239257
[list of supported languages]: https://2captcha.com/2captcha-api#language
240258
[examples directory]: /examples
259+
[asyncio]: https://docs.python.org/3/library/asyncio.html

0 commit comments

Comments
 (0)