Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Those who don't understand Linux are doomed to reinvent it, poorly. -- unidentified source


devel / comp.lang.python / Re: Using a background thread with asyncio/futures with flask

SubjectAuthor
o Re: Using a background thread with asyncio/futures with flaskdieter.maurer

1
Re: Using a background thread with asyncio/futures with flask

<mailman.14.1711128828.3468.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=29722&group=comp.lang.python#29722

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: dieter.maurer@online.de
Newsgroups: comp.lang.python
Subject: Re: Using a background thread with asyncio/futures with flask
Date: Fri, 22 Mar 2024 18:28:25 +0100
Lines: 28
Message-ID: <mailman.14.1711128828.3468.python-list@python.org>
References: <8a7231df-c30c-4fa6-9daa-546b3453b547@thomasnyberg.com>
<09efe843-195e-48c0-a9cb-6fe05e3a6921@solute.de>
<dcdef19d-cca1-4ce3-af8d-ae79abf79ec8@thomasnyberg.com>
<26109.49081.441135.764314@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de Vu7WNw28YIRPvC7jpFVAWg02KR8vk8Eev3OQ4sk2G5hQ==
Cancel-Lock: sha1:WK+EDbh5XBoGkK59GEGDeE2NxAM= sha256:G7/pnKiylMAPe4UJNwsH98mK2dtzToNlqNLJGB6QsOE=
Return-Path: <dieter.maurer@online.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=online.de header.i=dieter.maurer@online.de
header.b=eBF5biHb; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'thread': 0.05; '(to':
0.07; 'loop': 0.07; 'received:212.227': 0.07; 'cc:addr:python-
list': 0.09; 'meant': 0.09; 'other.': 0.09;
'received:212.227.126': 0.09; 'skip:` 10': 0.09; 'skip:` 20':
0.09; 'tasks,': 0.09; 'cc:no real name:2**0': 0.14; 'exhibits':
0.16; 'subject:thread': 0.16; 'thread.': 0.16; 'calls': 0.19;
'cc:addr:python.org': 0.20; 'exception': 0.22; 'received:de':
0.23; 'cc:2**0': 0.25; 'library': 0.26; 'expect': 0.28; 'think':
0.32; 'associate': 0.32; 'objects': 0.32;
'received:kundenserver.de': 0.32; 'received:mout.kundenserver.de':
0.32; 'subject:Using': 0.32; 'but': 0.32; 'same': 0.34; 'header
:In-Reply-To:1': 0.34; 'special': 0.37; 'using': 0.37;
'received:192.168': 0.37; 'single': 0.39; 'use': 0.39;
'scheduled': 0.39; 'wrote': 0.39; 'appears': 0.40; 'likely': 0.61;
'received:212': 0.62; 'activities': 0.65; 'future': 0.72;
'schedule': 0.73; 'reasons': 0.84; 'callback': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=online.de;
s=s42582890; t=1711128820; x=1711733620; i=dieter.maurer@online.de;
bh=ENVkGBWbdSP2K/orV/DlqzGbE6lUFKmgzjDUZKNjSao=;
h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:
References;
b=eBF5biHbSgBjW+mRElJzGkaqWXkw2GbQT55VRs7Dt6x8NQpPRsshJEZLpXPmDBTE
IDB/oyk9uvGe9kwC/ZHHugx2BuRMzBrduIp1hOrw28WabOerc3f0Bn/vy+nWJ/h2a
FFW06tTr9YnVoU470Yibfn2KGZnJKAFEob5xZ+Xh5Tn5Lk/HUqJuCW9gaNdzJ1+BC
naBP6ej4UH0cKVudgcBuwMflWbc8Tzystwa1pIkS8AhqeszJlMeSOINU8u07iuq04
S5m/KEdtTAlRycPLrT3cgOlbDuOAtl7xDxvzN0kafG2sbm5kgMQ1Vt2Hiyz80Vmut
3cg2dKi7C2gq5Ig3Ew==
X-UI-Sender-Class: 6003b46c-3fee-4677-9b8b-2b628d989298
In-Reply-To: <dcdef19d-cca1-4ce3-af8d-ae79abf79ec8@thomasnyberg.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
X-Provags-ID: V03:K1:hdAf5SFsylWzpSiwnSAlJguAOW83jEAjqkBBCwVyPI2VoozXE4L
F4L7J53tSlZ0ZD8yZm1NGgDEsTPHGnuGTW3wf/GZCbSbKg2tIDfOJKcmiqrbKLblNIWRMNr
DiBxIy6/A1XoSrowVwx5VXq0L5UQJwsO5Q1kwXTbj+Thf+2h3gejh4aeD0SM9rGVF3IJd/V
PAyBUwiUtU5iCCwuhCzHw==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:7qcOVKA+yls=;ySQ0g9gfI1BAI1NKvnBXZMVWEXv
ptdGKZ6+7QIDVLRYBcjVwsvYV65HtufR/v7nW37NPlINMLzJ+R0sY0b/4usorgXPLFJ9vz6Op
m2AKHoJc6kfI9Du2QVlgMkqqlClDJ30fGKc0a5SJokjRyn7dCQj8q+fBLxYs62Gt+BJL4dWGl
dZEHgidgOlmnft67on9yXFin2Vo6Fl0W/s++1PwQv2xZ3u+eYkjTttbyaXEf0EuKWzwCZT9A2
kOc1QKGYdGdkbZrazVjJZLPXP2MIy+pIdwS20HzYcf5EbrdptgXs0Z3MIP3Zx1PTmpADg9oUZ
RrWCQp9SBPyccSSUpq5btVWcCErXAMpYCfWpVZ4pF2u2bCmkUFNBzO82WQpnw2mjwCX3XcPws
kK7dsyGiB2BfKDpk5i1p4x9edWCgiHSiBHW0makUe0cl4HUaSclRkh2ttFJpP1ilNCpo9QdXM
23/PTZAzgUj0XYB8B6jtOYsDIlMRai84rJbMA5dxGDPVq1cj5hke9sN0YOrpjrtin5kXujRG0
0VkeCkAE5tE304KH88Bcv56XjFYrXGg2EGTuWr3QeEztgCicWWvhDq6Rt9qF6BJhaPNdtxQYP
j33Q53Wcx4/wavOZorwIxQCzl12wuQaAl7OiSW97HIxA9yGAhdezCO9jBWDyxaY8f68grQF7g
KvXzfeitLbv9WLHqx9CuIdOlObFaRTA9BALPLOjFwRAFkw59uU0l6XN5yuoKwKYFAahRklWye
3dwz63xYyrA32d6BnD7kFYGqFXrE4/Jr0V26UI4kkVWyMY5N3pKxjU=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <26109.49081.441135.764314@ixdm.fritz.box>
X-Mailman-Original-References: <8a7231df-c30c-4fa6-9daa-546b3453b547@thomasnyberg.com>
<09efe843-195e-48c0-a9cb-6fe05e3a6921@solute.de>
<dcdef19d-cca1-4ce3-af8d-ae79abf79ec8@thomasnyberg.com>
 by: dieter.maurer@online.de - Fri, 22 Mar 2024 17:28 UTC

Thomas Nyberg wrote at 2024-3-22 11:08 +0100:
> ... `future` use across thread boundaries ...
> Here's an example using just the standard library that
> exhibits the same issue:

I think all `asyncio` objects (futures, tasks, ...)
are meant to be used in a single thread.
If you use them across different threads, you must do special things.

Note that an `await(future)` registers a callback at *future*.
When the future gets its result or exception, the registered callback calls
are scheduled via `self._loop.call_soon`.
`call_soon` must be called from the `asyncio` thread (to which `self._loop`
belongs). A different thread may schedule activities for a loop
but it must use `call_soon_threadsafe` (not `call_soon`).

I would expect that the forbidden `call_soon` call raises an exception
which for reasons I do not know appears to be hidden.

For use across thread boundaries, you likely will use
`concurrent.Future` (not `asyncio.Future`).
You can use `asyncio.futures._chain_futures` to associate
an `asyncio.Future` with a `concurrent.Future`.
Then the fate (result or exception set) of one will be reflected in the other.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor