Server time out


For whatever reson, I am getting a server timed out error when trying to OCR files:

import frappe

def PDF_parser(file):

	import ocrmypdf
	import os

	file = os.getcwd() + '/site1.local' + file
		ocrmypdf.ocr(file, file, deskew=True, progress_bar=False)
		return('file was OCRed')

		return('file was not OCRed')

Any ideas why this times out (even when there is an exception)?
When trying to run manually it takes no more than 15 seconds to run this function for whaterver file being tested.
I call it like this:

frappe.ui.form.on('Raw Materials', {
	pdf_file(frm) {{
			method: "",
			args: {
			'file': frm.doc.pdf_file
			freeze: true,
			callback: (r) => {
			alert (r.message);

Any ideas?