I amd using 32-bit Python 3.13 on Windows 11.
I am writing a server that talks to a Pervasive database using asyncio and aioodbc.
I run it from the command prompt.
I notice it is very slow to shutdown (just over 3 seconds).
Perhaps not important in real life use, but an irritation during development
when I want to modify the code, shut down the server, and restart it.
Here is a vastly simplified program to demonstrate the problem:

import sys, os
import time
import asyncio
import aioodbc

CONNECTION_STRING = "Driver={Pervasive ODBC Client Interface};DBQ=MYDATABASE"
# Substitute your own database or connection string here.

async def Run():
    pool = await aioodbc.create_pool( dsn = CONNECTION_STRING )
    # A real program would do its work here.
    pool.close()
    await pool.wait_closed()
    print(f'{time.strftime('%H:%M:%S')} Exiting')
    sys.exit() # or os._exit(0).  Takes just over 3 seconds.

asyncio.run( Run() )


As it happens my Windows command prompt is configured to display the time (h,m,s) and when the prompt appears the time has moved on by 3 sec or occasionally 4 sec from the time displayed by the program. Note that very little time is needed to explicitly close the pool (as the above program does). Can someone please tell me what is going on, and if I can speed up the program shutdown?
A quick-and-dirty hack is fine as far as I am concerned.
I have a suspicion that the problem is Pervasive-related, and might not occur with other databases,
but even so I would have thought that there should be a Python work-around.

I tried putting all the program code into a main function and running that function with cProfile. What happened was that I got about 400 lines of output very quickly, but then the program hung for about 3 seconds apparently doing nothing before returning to the command prompt. In other words it seems that Python is taking about 3 seconds to shut down AFTER executing my code.
The same thing happened when I ran
    python -m cProfile <program-name>
from the command prompt, except that now there were nearly 1000 lines of profile output. I tried including gc.collect() at the end of my code but it made no apparent difference
(cProfile said that gc.collect was run once and took 2 milliseconds).
Puzzled.
Best wishes
Rob Cliffe

--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to