kore-doc

The kore documentation found under https://docs.kore.io/
Commits | Files | Refs | README | git clone https://git.kore.io/kore-doc.git

commit a27c8d6b1ea0f0948cf5278b2ebbd9522d24d555
parent 873c23b9d54eeb98e231c9042fd6e7e51b4318df
Author: Joris Vink <joris@coders.se>
Date:   Sat, 29 Aug 2020 18:17:57 +0200

more fever induced hacking

Diffstat:
api/python.md | 84++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 81 insertions(+), 3 deletions(-)

diff --git a/api/python.md b/api/python.md @@ -69,11 +69,11 @@ koreapp = MyApp() * [fatal](#fatal) * [tracer](#tracer) * [task\_create](#taskcreate) - * [task\_kill](#taskkill) TODO + * [task\_kill](#taskkill) * [gather](#gather) * [suspend](#suspend) * [httpclient](#httpclient) - * [curl](#curl) TODO + * [curl](#curl) * [dbsetup](#dbsetup) TODO * [websocket\_broadcast](#websocketbroadcast) * [worker](#worker) TODO @@ -340,7 +340,7 @@ it returns from the parent function. ### Returns -Nothing +The unique task identifier that can be passed to kore.task\_kill(). ### Example @@ -357,6 +357,50 @@ def kore_worker_configure(): --- +# task\_kill {#taskkill} + +### Synopsis + +```python +kore.task_kill(taskid) +``` + +### Description + +Kills the coroutine task specified in the **taskid** identifier. + +The coroutine will immediately be killed. + +| Parameter | Description | +| --- | --- | +| taskid | The taskid identifier to be killed. | + +### Returns + +Nothing + +### Example + +```python +import kore + +async def coro(id): + while True: + await kore.suspend(1000) + print("i am coro %d" % id) + +async def kill(taskid): + await kore.suspend(5000) + kore.task_kill(taskid) + +def kore_worker_configure(): + task = kore.task_create(coro(1)) + + kore.task_create(kill(task)) +``` + +--- + # gather {#gather} ### Synopsis @@ -513,6 +557,40 @@ status, headers, body = await client.get(return_headers=True) --- +## Asynchronous libcurl client {#curl} + +The Python API in Kore contains a full asynchronous libcurl client that allows +you to fire off any protocol that libcurl supports from your Python code and +await their result. + +Before you can use the client you must set it up. + +**note** Kore must be built with CURL=1 for the curl handler to be included. + +```python +client = kore.curl(url) +``` + +| Parameter | Description | +| --- | --- | +| url | The URL to send the request to. | + +Once the libcurl object is created you can call handle.run() to perform +the call to the specified url. + +Additionally you can call handle.setopt() which behaves a lot like +the curl\_easy\_setopt() function. +### Example + +```python +handle = kore.curl("https://kore.io") + +# Run the libcurl handle. +data = await handle.run() +``` + +--- + # websocket\_broadcast {#websocketbroadcast} ### Synopsis