3

I have a set of blocking C-based functions. I am trying to find a way to make async calls to those blocking functions from python. Is there a way to do this from a python interface?

for example

 async def my_func():
      
      ffi.blocking_c_function()   # this will be blocking for seconds or even mins

This blocking function may take seconds or minutes before it finishes. How would be the behaviour of the above async python func?

I would appreciate any advice

BarisY
  • 171
  • 2
  • 4
  • 14
  • Are you looking to make that an ``async`` function (e.g. for ``asyncio``, ``trio``, etc.) or an "asynchronous" function (e.g. ``threading``, ``gevent``, ...)? – MisterMiyagi Apr 29 '21 at 12:24
  • I am looking to make that an async function (e.g asyncio) if possible, this would be easier than spawning another thread – BarisY Apr 29 '21 at 12:28
  • The straightforward way is to use ``asyncio`` to spawn and track a python thread. Is that sufficient for you? If the `blocking_c_function` does not need the gil, one could probably use a native thread that merely uses an ``asyncio`` flag to communicate success. – MisterMiyagi Apr 29 '21 at 14:15

0 Answers0