Home/ Reference/ Connection & Init

app.Quit()

Closes CorelDRAW entirely. Don't call it at the end of a batch job — it takes the user's unsaved documents with it. doc.Close() is safer.

Signature

app.Quit()

Notes

Closes CorelDRAW entirely. Don't call it at the end of a batch job — it takes the user's unsaved documents with it. doc.Close() is safer.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
import time

# Quit CorelDRAW entirely. Dangerous: unsaved user documents go with it
# Safer: close each document in reverse order first (saving if needed)
for i in range(app.Documents.Count, 0, -1):    # reverse order so indexes do not shift under you
    d = app.Documents.Item(i)                  # d : the i-th document
    if d.Dirty:                                # Dirty=True means unsaved changes
        d.Save()
    d.Close()                                  # close the document, keep the app running

app.Quit()                                     # quit CorelDRAW last
print("Quit")

What Quit actually means

app.Quit() exits the whole CorelDRAW application, it does not close a document. It closes every open document, including the ones somebody else is editing. That is why it is the most easily misused call in this reference — the tutorial line "and don't forget app.Quit() at the end" has caused a lot of damage.

Answer one question first: who started this instance

That is the only criterion. Code style and best practices are irrelevant:

To clean up, close only the documents you created. Decide this before you write the code, because the structure of everything that follows depends on the answer.

The process may survive Quit

Quit is a request, not an immediate termination. If COM references are still held — your Python variable still points at app, at a doc, or at a shape pulled out of a collection — the process stays alive in the background.

A genuinely clean shutdown is three steps: call Quit, release the references, confirm the process is gone:

Python
import time
import pythoncom

def shutdown(app, doc=None, timeout=20):
    # close the document first; letting Quit do it can raise a dialog
    try:
        if doc is not None:
            doc.Close()
    except pythoncom.com_error:
        pass
    try:
        app.Quit()
    except pythoncom.com_error as e:
        # the user may have closed it already; that is not an error
        print("already disconnected while quitting:", e.args[1])

    del doc
    del app                     # the important line: drop the COM reference
    time.sleep(1)               # give it a moment to actually exit

Note the del app. Plenty of people call Quit, never release the reference, and then complain that Task Manager is full of CorelDRW.exe.

What happens if you touch app after Quit

You do not get a polite "already closed". You get a COM error whose text is roughly "the object has been disconnected from its clients", HRESULT 0x80010108 (RPC_E_DISCONNECTED). When you see that code, check whether you tried to read a property for logging after quitting — that is the most common self-inflicted case.

So: write down everything you need before Quit. Version, document count, durations, failure list — all of it goes to disk while the object is still alive.

A safer pattern for batch work

In a batch job over hundreds of files, the thing that matters is not Quit, it is closing each document cleanly. The order that holds up:

One real caveat about doc.Close(): if the document is flagged as modified, closing may ask whether to save. A batch job should never reach that point — your output is already exported to a file. If it is still asking, the pipeline is missing an export step or mutating the document without saving. That is a design problem, not a closing-technique problem.

When Quit is the right call and Close is not

The reverse case exists too: the script creates a temporary instance for one job and the instance should disappear afterwards. Closing documents one by one is just extra work there — Quit is cleaner. The criterion is unchanged: who owns the instance. Owner, Quit. Guest, Close.

About this section: Connection & Init

Connection & Init — connecting to CorelDRAW over COM.

Other entries in this section