<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def check_new_messages(client_id):
 """Check for new unread messages and send them to the custom api @param client_id: ID of client user """

    # Return if driver is not defined or if whatsapp is not logged in.
    # Stop the timer as well
    if client_id not in drivers or not drivers[client_id] or not drivers[client_id].is_logged_in():
        timers[client_id].stop()
        return

    # Acquire a lock on thread
    if not acquire_semaphore(client_id, True):
        return

    try:
        # Get all unread messages
        res = drivers[client_id].get_unread()
        # Mark all of them as seen
        for message_group in res:
            message_group.chat.send_seen()
        # Release thread lock
        release_semaphore(client_id)
        # If we have new messages, do something with it
        if res:
            print(res)
    except:
        pass
    finally:
        # Release lock anyway, safekeeping
        release_semaphore(client_id)