This is a hard question, and the answer is "it depends".
Home Equity: Each owner on a deed is entitled to a "homestead exemption" which is currently $165,500 in NYC. If one joint owner dies, then the survivor will only have one exemption. Thus, if the house has more than $165,500 in equity, you should consider filng before death of your spouse.
Whose Debt is it? if most of the debt is the ill spouse's then there may not be a need for bankruptcy. Unless there are assets that pass under a will, credit cards will not get paid after the cardholder dies. Protected assets; jointly owned homes, joint bank accounts, life insurance.
Could there be a medical malpractice case? If the survivor may have a medical malpractice case, only a small portion of the net recovery could be retained by the surviving spouse. The scheduled creditors of both spouses would have to get paid from the proceeds.
Are there assets a bankruptcy trustee could take now? Any money taken out of retirment accounts to pay for current living expense is no longer completely exempt once it is sitting in your regular bank account. Under certain circumstances we could protect about $13,000 in cash. If there is more than than, a bankruptcy filing should wait until it is spent on regular living expenses.
YES, THIS WAS A REAL CASE, AND THE DECISION WAS NOT TO FILE BANKRUPTCY.