If it appears from the petition for a writ of habeas corpus or from the documents thereunto annexed that the party is imprisoned or detained by virtue of any process under which any other person has an interest in continuing his imprisonment or restraint, the officer issuing the writ must endorse thereon an order requiring the applicant, or someone else for him, to give notice to such person, or to his attorney, of the issue of the writ and of the time and place at which it is returnable, in order that he may, if he thinks proper, appear and object to the discharge of the party who is imprisoned. If such notice is not given, when the party who is entitled to it is within 50 miles of the place of examination, the party who is imprisoned must not be discharged.