Hello all
Is there a way to run a slow u2py operation in background?
I ran some tests and the Universe Python seems to not support parallel execution due to GIL, so I discarded Python's native threads.
With async routines the execution gets blocked on u2py calls:
BASIC code:
>CT UP ADORMIR
ADORMIR
0001 SLEEP 50
0002 CRT 'me despierto'
0003 RETURN
0004
>
Python code:
import asyncio
import time
from datetime import datetime
import u2py
MAX_TIME = 60*2
INTERVALO_LARGO = 30
INTERVALO_CORTO = 1
async def corutina_rapida():
i = 0
while i < MAX_TIME/INTERVALO_CORTO:
print(f'{i} - {datetime.now()} - HOLA')
await asyncio.sleep(INTERVALO_CORTO)
i += 1
return 'OK'
async def corutina_dormilona_universe():
i = 0
c = u2py.Command('ADORMIR')
while i < MAX_TIME/INTERVALO_LARGO:
r = c.run()
print(f'{i} - {datetime.now()} - A DORMIR - {r}')
i += 1
await asyncio.sleep(0)
return 'OK'
async def lanza_corutinas():
lp = u2py.Command('LOGTO POSVENTA5').run()
await asyncio.gather(corutina_rapida(), corutina_dormilona_universe())
def main_test():
asyncio.run(lanza_corutinas())
When the u2py Command is running the other coroutine is blocked.
Is there a way to run this commands so that they don't block execution?
------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------