Closed BenH4 closed 4 years ago
I succesfully solved my problem by tinkering with the convertapi code a bit. I added the possibility to disable the multiprocess mapping, here are the changes I made:
import convertapi
from .task import Task
def convert(to_format, params, from_format = None, multiproc=True, timeout = None): task = Task(from_format, to_format, params, multiproc, timeout = timeout) return task.run()
def user(timeout = None): return convertapi.client.get('user', timeout = timeout)
- And to convertapi/tasks.py:
class Task: def init(self, from_format, to_format, params, multiproc, timeout = None): self.from_format = from_format self.to_format = to_format self.params = params self.timeout = timeout or convertapi.conversion_timeout self.multiproc = multiproc
self.default_params = {
'Timeout': self.timeout,
'StoreFile': True,
}
def __normalize_params(self):
params = {}
for k, v in self.params.items():
if k == 'File':
params[k] = file_param.build(v)
elif k == 'Files':
if self.multiproc:
results = utils.map_in_parallel(file_param.build, v, convertapi.max_parallel_uploads)
else:
results = map(file_param.build, v)
for idx, val in enumerate(results):
key = '%s[%i]' % (k, idx)
params[key] = val
else:
params[k] = v
params.update(self.default_params)
return params
I have not tested the changes with anything else than the merging of PDFs from local files.
@laurynas-baltsoft Should we add the fix suggested by @BenH4 ?
Hey @BenH4, have you tried adjusting max_parallel_uploads
param? You could try with pool size 1:
convertapi.max_parallel_uploads = 1
Hi @laurynas-baltsoft, actually I remember trying to use 1 for the pool-size and it open one more tkinter instance. I also tried 0 but obviously it crashed.
Hey @BenH4, adjusted not to use multiprocessing if max_parallel_uploads
is set to 1. It is released in v1.3.0
. Could you please check if it solves the issue?
I'm using the module convertapi to merge pdf files in a tkinter application in Python3.8. When I have some tkinter window in my code, if
convertapi.convert('merge', {'Files': input_files})
is called, multiple instances of the tkinter window open. My script:A picture of the phenomenon It's a very weird behavior since even when I call the function in the console with the tkinter window closed beforehand, multiple windows still open up. I'm guessing there is some kind of incompatibility between the two modules but I can't be sure. If it can help, there are 10 more instances of the tkinter window that open up when the funstion is called.
After a bit of digging, it seems that it is due to the fact that multiple processes can't share the same root window in tkinter. And indeed in the code, there is a multiprocessing operation when multiple files are converted. In convertapi/task.py:
And convertapi/utils.py: