diff --git a/examples/python-async/README.md b/examples/python-async/README.md index 97451e3..422a07f 100644 --- a/examples/python-async/README.md +++ b/examples/python-async/README.md @@ -3,9 +3,11 @@ Kore python async/await examples. This example also shows off the asynchronous HTTP client support and requires libcurl on your machine. +Requires that Kore is built with PYTHON=1 CURL=1 + Run: ``` - $ kodev run + $ kore app.py ``` Test: diff --git a/examples/python-async/src/setup.py b/examples/python-async/app.py similarity index 78% rename from examples/python-async/src/setup.py rename to examples/python-async/app.py index ab01e61..ee77372 100644 --- a/examples/python-async/src/setup.py +++ b/examples/python-async/app.py @@ -16,8 +16,13 @@ import kore -from async_queue import queue_helper +import async_http +import async_queue +import async_socket +import async_process +import async_process -# Kore worker started, start the queue helper coroutine. -def kore_worker_configure(): - kore.task_create(queue_helper()) +kore.server(ip="127.0.0.1", port="8888", tls=False) +kore.domain("*") + +kore.task_create(async_queue.queue_helper()) diff --git a/examples/python-async/src/async_http.py b/examples/python-async/async_http.py similarity index 97% rename from examples/python-async/src/async_http.py rename to examples/python-async/async_http.py index 854919b..1e20bfa 100644 --- a/examples/python-async/src/async_http.py +++ b/examples/python-async/async_http.py @@ -21,6 +21,7 @@ import kore # Handler called for /httpclient +@kore.route("/httpclient", methods=["get"]) async def httpclient(req): # Create an httpclient. client = kore.httpclient("https://kore.io") diff --git a/examples/python-async/src/async_lock.py b/examples/python-async/async_lock.py similarity index 97% rename from examples/python-async/src/async_lock.py rename to examples/python-async/async_lock.py index dceb1a9..20a93da 100644 --- a/examples/python-async/src/async_lock.py +++ b/examples/python-async/async_lock.py @@ -28,6 +28,7 @@ import kore # The shared lock lock = kore.lock() +@kore.route("/lock", methods=["get"]) async def async_lock(req): # A kore.lock should be used with the "async with" syntax. async with lock: diff --git a/examples/python-async/src/async_process.py b/examples/python-async/async_process.py similarity index 98% rename from examples/python-async/src/async_process.py rename to examples/python-async/async_process.py index 2add851..95d4604 100644 --- a/examples/python-async/src/async_process.py +++ b/examples/python-async/async_process.py @@ -25,6 +25,7 @@ import kore import json +@kore.route("/proc", methods=["get"]) async def async_proc(req): # # You may specify a timeout when creating the kore.proc object. diff --git a/examples/python-async/src/async_queue.py b/examples/python-async/async_queue.py similarity index 97% rename from examples/python-async/src/async_queue.py rename to examples/python-async/async_queue.py index 03fd100..ffb6949 100644 --- a/examples/python-async/src/async_queue.py +++ b/examples/python-async/async_queue.py @@ -36,6 +36,7 @@ async def queue_helper(): # Send it on the received queue. obj["rq"].push(msg) +@kore.route("/queue", methods=["get"]) async def async_queue(req): # Create our own queue. rq = kore.queue() diff --git a/examples/python-async/src/async_socket.py b/examples/python-async/async_socket.py similarity index 95% rename from examples/python-async/src/async_socket.py rename to examples/python-async/async_socket.py index baca675..f0dbf77 100644 --- a/examples/python-async/src/async_socket.py +++ b/examples/python-async/async_socket.py @@ -23,6 +23,7 @@ import kore import socket +@kore.route("/socket", methods=["get"]) async def async_socket(req): # Create the socket using Pythons built-in socket class. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -51,6 +52,7 @@ async def async_socket(req): conn.close() +@kore.route("/socket-test", methods=["get"]) async def socket_test(req): # Delay response a bit, just cause we can. await kore.suspend(5000) diff --git a/examples/python-async/conf/build.conf b/examples/python-async/conf/build.conf deleted file mode 100644 index 87c8b7b..0000000 --- a/examples/python-async/conf/build.conf +++ /dev/null @@ -1,34 +0,0 @@ -# python-async build config -# You can switch flavors using: kodev flavor [newflavor] - -# Set to yes if you wish to produce a single binary instead -# of a dynamic library. If you set this to yes you must also -# set kore_source together with kore_flavor. -single_binary=yes -kore_source=../../ -kore_flavor=PYTHON=1 CURL=1 NOTLS=1 DEBUG=1 - -# The flags below are shared between flavors -cflags=-Wall -Wmissing-declarations -Wshadow -cflags=-Wstrict-prototypes -Wmissing-prototypes -cflags=-Wpointer-arith -Wcast-qual -Wsign-compare - -cxxflags=-Wall -Wmissing-declarations -Wshadow -cxxflags=-Wpointer-arith -Wcast-qual -Wsign-compare - -# Mime types for assets served via the builtin asset_serve_* -#mime_add=txt:text/plain; charset=utf-8 -#mime_add=png:image/png -#mime_add=html:text/html; charset=utf-8 - -dev { - # These flags are added to the shared ones when - # you build the "dev" flavor. - cflags=-g - cxxflags=-g -} - -#prod { -# You can specify additional flags here which are only -# included if you build with the "prod" flavor. -#} diff --git a/examples/python-async/conf/python-async.conf b/examples/python-async/conf/python-async.conf deleted file mode 100644 index 6d68786..0000000 --- a/examples/python-async/conf/python-async.conf +++ /dev/null @@ -1,28 +0,0 @@ -# python-async configuration - -server notls { - tls no - bind 127.0.0.1 8888 -} - -python_path src - -python_import ./src/setup.py -python_import ./src/async_lock.py -python_import ./src/async_queue.py -python_import ./src/async_process.py -python_import ./src/async_socket.py -python_import ./src/async_http.py - -domain * { - attach notls - - route /queue async_queue - route /lock async_lock - route /proc async_proc - - route /socket async_socket - route /socket-test socket_test - - route /httpclient httpclient -} diff --git a/examples/python-async/src/init.c b/examples/python-async/src/init.c deleted file mode 100644 index d40c00b..0000000 --- a/examples/python-async/src/init.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 Joris Vink - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include - -/* Let kore handle the default option parsing. */ -void -kore_parent_configure(int argc, char **argv) -{ - kore_default_getopt(argc, argv); -}