Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <mailman.17.1711136505.3468.python-list@python.org>
Deutsch   English   Français   Italiano  
<mailman.17.1711136505.3468.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!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 20:28:31 +0100
Lines: 18
Message-ID: <mailman.17.1711136505.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>
 <26109.56287.684110.358617@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 1M9YSSACjPSOGUXNdSSANQdZJI2x31nUz++HapF65ehQ==
Cancel-Lock: sha1:0wsDSzqUlqX6i0a4iH1MCBnKzE0= sha256:lCfrXVIob1rUubqHnMGvyiqkgbAgz6Nt0fLBxCnMkIk=
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=ldkfTotp; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.013
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'thread': 0.05;
 'indirectly': 0.09; 'other.': 0.09; 'skip:` 10': 0.09; 'skip:`
 20': 0.09; 'exhibits': 0.16; 'received:217.72.192.75': 0.16;
 'skip:> 20': 0.16; 'subject:thread': 0.16; 'thread.': 0.16;
 'to:addr:python-list': 0.20; 'exception': 0.22; 'received:de':
 0.23; 'library': 0.26; 'associate': 0.32;
 'received:kundenserver.de': 0.32; 'received:mout.kundenserver.de':
 0.32; 'subject:Using': 0.32; 'same': 0.34; 'header:In-Reply-To:1':
 0.34; 'using': 0.37; 'received:192.168': 0.37; 'means': 0.38;
 'use': 0.39; 'wrote': 0.39; 'likely': 0.61; 'above': 0.62; 'here':
 0.62; 'received:217': 0.67; 'future': 0.72
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=online.de;
 s=s42582890; t=1711136496; x=1711741296; i=dieter.maurer@online.de;
 bh=XUQTMGDc3j2dE6v6zlkZ6/UZx0YmqCW53n08APD5Emg=;
 h=X-UI-Sender-Class:Date:From:To:Subject:In-Reply-To:References;
 b=ldkfTotpnYHmXstH2FCjxBe6EHkwtsFC+0xOEXRYP8srV3QaUY0gtjAiO0eGhiKh
 hZUjl5XJrz+hBKbDOnZPy179UwktvOF+0jqvAQI213uuS4PH/YQrN43m3h0/Sugy+
 7rGoCRmxWKd1H3Lb3lOJleTDP0VC92vSn4MNSabfWfVKhaQCS42Q/nq1e0hTKl7CJ
 Ph5fYznWKGftWpDtcmtftTd02PCjSkPunzkR3jySqqFYITO9scHoDr1l+xwS0g7LH
 D/DJpmmUplGumCWaQFwMLQy0ufn9leBKCNuNEn99FB6RaaCBDahVflzsNSvuSxq+5
 s331vkc7kLzTLH6gMg==
X-UI-Sender-Class: 6003b46c-3fee-4677-9b8b-2b628d989298
In-Reply-To: <26109.49081.441135.764314@ixdm.fritz.box>
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:Ij94md9d82lP9Ufz1VbL1gl73lnewQh+2w5VPK/+/BeoJrVbAb3
 suAse6gCmsUvgXGn/bWhcQQAafV22yoKE1rQ8ggfikzz+U8PkAr75KTHm7BskOBYFHKarbu
 N6f61oasqLr27evpr98+XGDOyRamCevVPqlBIwPlssklYOA+5hEgjONJcZd95aEVU7QUoeG
 96eYTILADxjRed/yWGtZw==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:LyWKBVfyYZQ=;5L1DYILBg4B8JrK1Qb4HPZauEAb
 T0VGHlS5V0sUzpAs6YOpNoXQPgb2qryblbmkvkDaOL+YwvIfZvDZuI9DcIaW3fdGxBqzXyR84
 m+bjJtT+MKea/ZHy5yCJ928CHZyzTbRoE7KYhYH7Tkq9numBgGyHTBMp3HsbEMmoNash+yxka
 U5DZnhp96XT0KNNzGHzdICtyFZ9865s3/4Zg8HCiYzCCGHHdtJlLN3lArR0mKll3+78ydkrsh
 tGzAULvvauwxbwap/SDOAGc3VAL7or86XncnOdSrc0a2+B82xznQg+antBDjoJOpEekhdBQvj
 OhkpUOYhQjuWl0WeD4oK8g6bfLgZVs7HV9AasoQGd4cJLKtwmM+FSme9rlbfaeomjMFxKxWIl
 hDdZnF7znDZNyLAJDdBTavAxgqyXwPpPAPQ88ysXrzJhTI9qhhg4ZEe/gTMkdefQ+gLof/jbF
 h8ZewbqeMBF8ofrTHWm4cOurNoUAqURvI9vw8xRmzOjVWfzdCwdf9BnvU5aMyPeiIQhPc8vht
 9caEiuq80hnbS/07yYbfIRU/qKGhwfonI2uSch6DlMZxKx5e3JSNCY7tspMSGMYioKS3hISJV
 txHmSjyryaRhGIzVlgiZFPDQsMoEcEzstfZij3SgzXdAgGEq1CifD/jzskuBo6A9tOSnseudi
 KWaceBhqF2FyuM4uq1NxvlvGI4ZFmDVnnzunatj5jf+QmkkhCYzcCxWtOoQ7dxN38+4H5JBBX
 qh9StUnIo/Moa59SJAwrMlhgLnu3A5pkrGQ4iWb7vdXt+il7v2l/kA=
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.56287.684110.358617@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>
 <26109.49081.441135.764314@ixdm.fritz.box>
Bytes: 5714

dieter.maurer@online.de wrote at 2024-3-22 18:28 +0100:
>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:
> ...
>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 o=
ther.

You must not set the result/exception for a future in a "foreign" thread
("foreign" here means one not associated with the future's loop).
An aternative to the solution sketched above is to set the result
indirectly via `loop.call_soon_threadsafe`. This way, the
result is set in the futures "native" thread.