-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Description
While trying to find a good way to detect when there is no network connection while in a idle_check() loop, I discovered that if the network connection to the IMAP server is severed after idle() has been called, a call to idle_close() just hangs unless the network connection is restored.
with IMAPClient(host) as server:
server.login(address, password)
select = server.select_folder("INBOX", readonly=True)
while True:
i = 0
print("IDLE starting...")
server.idle()
print("IDLE started")
# Reset IDLE state every 30 seconds to ensure IMAP server connection exists
while i < 6:
responses = server.idle_check(timeout=5)
print("Server sent:", responses if responses else "nothing")
i += 1
print("Stopping IDLE...")
server.idle_done()
print("IDLE stopped")
The purpose of stopping the IDLE state and restarting it every 30 seconds is to ensure a connection to the IMAP server still exists since idle_check() does not detect a connection loss.
Steps to Reproduce
- Connect to IMAP server and call idle()
- Disable network connection on client (I did this by disabling my wired NIC in NetworkManager)
- Code hangs at server.idle_done() while no network connection
Code Output
IDLE starting...
IDLE started
Server sent: nothing
Server sent: nothing
Server sent: nothing # NIC disbled at this point
Server sent: nothing
Server sent: nothing
Server sent: nothing
Stopping IDLE... # Code hangs here unless network connection restored
My Setup
- Linux Mint 20
- Python v3.8.10
- IMAPClient v2.2.0 (installed via pip)