
99 Cal.App.2d 119 (1950)
HANS P. JEPSEN, Appellant,
v.
DEAN SHERRY et al., Respondents
Civ. No. 3982. 
California Court of Appeals. Fourth Dist.  
Aug. 21, 1950.
 Hans P. Jepsen, in pro. per., for Appellant.
 William H. Macomber and Martin & Mahedy for Respondents.
 BARNARD, P. J.
 This action was brought on September 14, 1946, to recover a balance due on an oral building contract, and to foreclose a lien on defendants' property. A cause of action on quantum meruit was included by amendment. The record shows the following proceedings: A demurrer was filed on October 11, 1946, and an amended complaint December 22, 1947. A demurrer filed on January 2, 1948, was amended January 23, and sustained with leave to amend on February 13. A second amended complaint was filed on March 9, a demurrer March 18, and an amended demurrer on April 7. On June 16, 1948, an answer was filed. On July 6, the plaintiff filed a request to have the case set for trial, and on July 8 the defendants demanded a jury. The court set the case for trial on May 26, 1949.
 On May 20, 1949, the defendants served and filed notice of a motion to dismiss the action for failure to prosecute, under sections 583 and 1190 of the Code of Civil Procedure, in that it had not been brought to trial within two years. At the same time they noticed a request for permission to file an attached amended answer and a cross-complaint. Both motions were noticed for May 26, the day the action was to be tried. The court granted the first motion and entered a judgment dismissing the action "but without prejudice to such other actions, if any there be, legally available to plaintiff." This appeal followed.
 [1] It is well settled that a court has an inherent and statutory power to dismiss an action for a failure to prosecute it with diligence; and that its action should not be disturbed unless an abuse of discretion clearly appears. However, the two years mentioned in these statutes is not an arbitrary limit to be followed in all cases, but was intended as a general guide in determining whether or not a "want of prosecution" *121 appears and, if so, whether this power should be used in view of the entire situation. This discretion is one controlled by legal principles and is to be exercised in accordance with the spirit of the law and with a view to subserving, rather than defeating, the ends of substantial justice. (Raggio v. Southern Pac. Co., 181 Cal. 472 [185 P. 171].) Each case must be decided on its own peculiar features and facts. (First National Bank v. Nason, 115 Cal. 626 [47 P. 595].) [2] It is a well established policy of law to favor the avoidance of litigation by compromise. (Hamilton v. Oakland School Dist., 219 Cal. 322 [26 P.2d 296].) While not always controlling, this sometimes has an important bearing. In Ferris v. Wood, 144 Cal. 426 [77 P. 1037], an order of dismissal was reversed, it appearing that the debt was owed, and that the delay occurred through the plaintiff's desire to effect a compromise. The court held that an excuse for the delay reasonably appeared and that in such a matter, unlike some others, a trial judge is in no better position than an appellate court in determining whether substantial justice has been done. The court then expressed the opinion that the dismissal there involved had tended to defeat, rather than to subserve, the ends of substantial justice.
 [3] It was stated at the oral argument, and not denied by their counsel, that during the negotiation the defendants had offered to pay the plaintiff $2,500. While this was not before the trial court, the pleadings in the record strongly indicate that a considerable amount was justly due. The complaint alleged an oral contract, in February, 1946, by which plaintiff was to furnish materials and do certain remodeling and construction work, as directed by defendants, on a cost plus basis; that he proceeded with the work and followed instructions until June 7 when he was directed to cease work; and that a balance of $9,066.42 is due. In their answers the defendants denied making any agreement, that the plaintiff had done any work, and that any material or labor had been furnished. In their cross-complaint they alleged the making of an oral contract by which the plaintiff agreed to do certain remodeling and construction work; that he commenced work on February 10 and abandoned it on June 6, when it was only partially completed; and that they caused the work to be completed at their own expense, it being necessary to correct "certain errors, defects and omissions." There is no allegation of any original contract price, or of *122 any price for any particular part of the work. While it is alleged that "certain" corrections were made, nothing is said as to their cost. While it is alleged that additional work was done, there is nothing to indicate that the work done by the plaintiff during four months was of no value. Except for the corrections, which may have been slight, there is nothing to indicate that most of plaintiff's work should not be paid for, or that the defendants' total cost would then be more than it otherwise would have been. The pleading is somewhat evasive, and leaves a distinct impression that while a partial offset was claimed a large amount was justly due the plaintiff.
 Aside from the pleadings, two affidavits only appear in the record. The one in support of the motion to dismiss is devoted entirely to the matter of prejudice in that two witnesses, who were employed on the job, had left town. It goes unduly into the merits of the case by reciting in great detail what these witnesses would testify. The other, by plaintiff's then attorney, alleged among other things that the parties were trying to settle the controversy and the defendants agreed to, and did, engage an architect to inspect and report on the work; that from December, 1946, to December, 1947, affiant and defendants' attorneys hoped and thought that a settlement could be effected and further litigation avoided; that when an answer was finally filed a request for setting was immediately made; that because of defendants' demand for a jury, and the congested calendar, "it was impossible for said court to set the case for trial prior to May 26th, 1949"; that a large number of workmen who were employed on this job are available to defendants as witnesses, if two others are not; and that affiant is willing to stipulate to the taking of a deposition. The facts thus stated were not disputed or otherwise contradicted.
 In most of the cases where such a dismissal has been sustained either nothing was done by the plaintiff or no valid excuse for the delay was shown, and no unusual circumstances appeared. Unreasonable delay in litigation should be avoided, but all the circumstances should be carefully considered before a plaintiff is denied relief without a hearing. While it appears here, technically, that more than two years had elapsed before the trial date and that some of the delay was probably unnecessary, the excuse for the delay is not entirely unreasonable and there are other considerations which should not be overlooked. *123
 One circumstance is that the main defendant is a judge of the same court. "Period." Most of the delay occurred before the first amended complaint was filed, and while both sides believed that a settlement could be reached. Much more was caused by the defendants and as a result of four demurrers filed, three of which were never heard. While this is not controlling it is one of the circumstances. When an answer was filed the plaintiff moved at once, and well within the two years, to set the case for trial. The defendants' demand for a jury, while rightful, naturally caused an additional delay. In response to the timely request thus made the court set the case for trial, the first available date being beyond the two-year period. Nothing was then done until, at the last minute, notice was given of a motion to dismiss. Moreover, this was accompanied by a desired cross-complaint which materially changed the picture. It thus appeared at the hearing that a large amount of work had admittedly been done, and that a substantial amount was probably due. The court clearly recognized this, by making the order of dismissal without prejudice to seeking other relief if this could possibly be done. The order appears to have resulted from a feeling that it was required by these statutes, rather than from an exercise of real discretion.
 The circumstances here were unusual, all of them should be considered, and an unjust effect should not be given to this procedural rule, which is merely optional. The defendants may owe the plaintiff nothing, but under the circumstances substantial justice requires that this issue should be determined by a trial on the merits. The drastic order made is not sustained by the record before us, and an abuse of discretion clearly appears.
 The judgment of dismissal is reversed.
 Griffin, J., and Mussell, J., concurred.
