Programs do not terminate when importing replit.db

Question:
Why do most files that I import the replit module refuse to terminate. Even if it is imported but goes unused it just hangs indefinitely after successfully running through the whole program. This goes for import replit, and from replit import db.

I recently typed a simple 2 lines of code importing the module and printing in my testdatabase replit:

I then copied the same code to my newer importreplit replit however that one does terminate after 2 seconds which I assume is the time it takes to import the module and so I believe it is working as it should.

Please let me know what is going wrong and the differences between either project because I’ve tried it multiple times and this new importreplit project is the first one that actually terminates.

from replit import db
print('a')

For me, testdatabase terminates after 1s. And on the global (Free plan) cluster the initial run takes a few more seconds.

Expected behavior:

python3 myscript.py 

should execute the script, and return to bash shell prompt when finished.

Steps to reproduce:

Go to this Repl: https://replit.com/@latinlens/MAIN-LL. Go to the shell. Type:

python3 src/update_db_log.py my_argument

When I run this, the program executes properly but at the end it does not terminate and return to the bash prompt.

Alternatively, at the same command line, type:

python3 src/alternate_function.py my_argument

This is the same script but with the replit db interactions commented out. It executes properly and then exits.

I need this to terminate properly so I can update the replit db from a bash script. Also, I would be curious to know why this is happening.

nvm, it is a problem specifically with importing db.
It’s caused by the update which adds retries to the DB to prevent the code failing in the case that a rate limit is hit. If you don’t expect your code to hit rate limits, run in Shell:

poetry add replit@'~3.2.4,!=3.2.8||>3.5.0'

Remove the ||>3.5.0 if you don’t want the code to start stalling again in the case that a patch for this issue isn’t released in the next update to replit-py.
Or, of course, you could try and create a PR to fix this issue (I’ll try and get to it myself 2023-12-27T00:00:00Z)

because the issue doesn’t occur if your database is empty.
So, this is undefined behaviour and not just a change we should all be expected to “deal with”.

3 Likes