Asynchronous execution of synchronous functions

Diego Souza diegofpsouza at gmail.com
Mon Sep 26 13:15:59 EDT 2022


Did you check the ThreadPoolExecutor or the ProcessPoolExecutor? They
won't give you atomic writes unless you add a Lock or a Condition, but
they will execute your code in another thread or process.

https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor
https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor

Keep in mind that Python's threads have a global interpreter lock
(GIL) that prevents full parallelism. Processes work as expected, but
require IPC and pickable objects in and out.

-- 
Diego Souza
Wespa Intelligent Systems
Rio de Janeiro - Brasil


On Mon, Sep 26, 2022 at 1:01 PM <python-list-request at python.org> wrote:
> From: Axy <axy at declassed.art>
> To: Python List <python-list at python.org>
> Date: Mon, 26 Sep 2022 12:17:47 +0100
> Subject: Asynchronous execution of synchronous functions
> Hi there,
>
> is there a library to call functions in context of a thread? For
> example, as in asyncsqlite which has a thread and a queue I mean has
> anyone generalized such an approach already?
>
> If not, I'll do it myself, no problem.
>
> It's a kind of tiny stuff, like atomicwrites, which is quite difficult
> to dig out with modern search engines that have already rolled down to
> hell a decade ago.
>
> Axy.


More information about the Python-list mailing list