Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I find you lack of faith in the forth dithturbing. -- Darse ("Darth") Vader


devel / comp.lang.prolog / Re: Request for comments, async ISO core standard I/O

SubjectAuthor
* Re: Request for comments, async ISO core standard I/OMild Shock
`- Re: Request for comments, async ISO core standard I/OMild Shock

1
Re: Request for comments, async ISO core standard I/O

<ur771d$f2lp$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10287&group=comp.lang.prolog#10287

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janbu...@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.prolog
Subject: Re: Request for comments, async ISO core standard I/O
Date: Thu, 22 Feb 2024 11:18:20 +0100
Message-ID: <ur771d$f2lp$1@solani.org>
References: <7e154664-d8d9-46f2-ade4-9b9a7712a2den@googlegroups.com>
<1f804201-3aa6-4fbc-b1c3-f3887b304675n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 22 Feb 2024 10:18:21 -0000 (UTC)
Injection-Info: solani.org;
logging-data="494265"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.1
Cancel-Lock: sha1:vdCM8dG7//PlnUGv9nPcxjVYgGM=
X-User-ID: eJwNysERwDAIA7CVSoJNGYeasP8IzVN3wqZR4QQdg7nyB4ehQ31QvcpTARuOsT32U1qr1cjKauVNLaMdeZf/YkUWfw==
In-Reply-To: <1f804201-3aa6-4fbc-b1c3-f3887b304675n@googlegroups.com>
 by: Mild Shock - Thu, 22 Feb 2024 10:18 UTC

Now asyncifying I/O of Dogelog Player for Python.
I guess we got our head around the equivalents
of our Java Surrogate async/await constructs

"Promise" and "Coroutine". The key utilities among
asyncio are asyncio.to_thread an asyncio.run_coroutine_threadsafe,
which seem toe especially made for the two use cases.

Namely what was our Java Surrogate "Promise" wrapper,
now looks like here, what a wonderful code gem:

async def console_promise(buf, stream):
try:
res = await asyncio.to_thread(blocking_readline, stream.data)
stream.buf = res
stream.pos = 0
except IOError as err:
register_signal(buf, map_stream_error(err))

def blocking_readline(data):
return data.readline()

And what was our Java Surrogate "Coroutine" wrapper,
now looks like here, what a wonderful code gem again:

def test_sys_http_server_on(args):
[...]
obj.func = lambda req, res: baby_come_back(
launch_async(clause, buf, [req, res]), loop)

def baby_come_back(coro, loop):
future = asyncio.run_coroutine_threadsafe(coro, loop)
return future.result()

LoL

Re: Request for comments, async ISO core standard I/O

<ur77gq$f2u5$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10288&group=comp.lang.prolog#10288

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janbu...@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.prolog
Subject: Re: Request for comments, async ISO core standard I/O
Date: Thu, 22 Feb 2024 11:26:34 +0100
Message-ID: <ur77gq$f2u5$1@solani.org>
References: <7e154664-d8d9-46f2-ade4-9b9a7712a2den@googlegroups.com>
<1f804201-3aa6-4fbc-b1c3-f3887b304675n@googlegroups.com>
<ur771d$f2lp$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 22 Feb 2024 10:26:34 -0000 (UTC)
Injection-Info: solani.org;
logging-data="494533"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.1
Cancel-Lock: sha1:vi39p/hgobKvu08wYYMnJXLMrxA=
In-Reply-To: <ur771d$f2lp$1@solani.org>
X-User-ID: eJwFwYEBwCAIA7CXyixIz0GR/09Y4iss7mZ40Mdn2WZWRx5ZJ1dKfsroYnLUgB1CbfaAd1VzST6k8FV8+AEn6RRD
 by: Mild Shock - Thu, 22 Feb 2024 10:26 UTC

But its much more complicated than what we did
for JDK 21. Also starting the HTTP server in a separate
thread is extremly frightening:

def test_http_server_listen(args):
[...]
thread = threading.Thread(target=blocking_forever, args=(obj,))
thread.start()

def blocking_forever(obj):
obj.serve_forever()

Its extremly frightening since the Thread docu warns us:

Thread-based parallelism
In CPython, due to the Global Interpreter Lock,
only one thread can execute Python code at once
https://docs.python.org/3/library/threading.html

global interpreter lock
Also, the GIL is always released when doing I/O.
Past efforts to create a “free-threaded” interpreter
have not been successful
https://docs.python.org/3/glossary.html#term-global-interpreter-lock

But still, our use of asyncio.to_thread and
asyncio.run_coroutine_threadsafe capitalizes on
that the GIL is nevertheless released during I/O,

and we don't see much issue here.

Mild Shock schrieb:
> Now asyncifying I/O of Dogelog Player for Python.
> I guess we got our head around the equivalents
> of our Java Surrogate async/await constructs
>
> "Promise" and "Coroutine". The key utilities among
> asyncio are asyncio.to_thread an asyncio.run_coroutine_threadsafe,
> which seem toe especially made for the two use cases.
>
> Namely what was our Java Surrogate "Promise" wrapper,
> now looks like here, what a wonderful code gem:
>
>
> async def console_promise(buf, stream):
>     try:
>         res = await asyncio.to_thread(blocking_readline, stream.data)
>         stream.buf = res
>         stream.pos = 0
>     except IOError as err:
>         register_signal(buf, map_stream_error(err))
>
>
> def blocking_readline(data):
>     return data.readline()
>
>
> And what was our Java Surrogate "Coroutine" wrapper,
> now looks like here, what a wonderful code gem again:
>
> def test_sys_http_server_on(args):
>    [...]
>     obj.func = lambda req, res: baby_come_back(
>             launch_async(clause, buf, [req, res]), loop)
>
>
> def baby_come_back(coro, loop):
>     future = asyncio.run_coroutine_threadsafe(coro, loop)
>     return future.result()
>
> LoL


devel / comp.lang.prolog / Re: Request for comments, async ISO core standard I/O

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor