Reputation: 1
I'm facing a strange situation that I can't seem to understand: my main program is an application built with PySide6 that launches several QProcesses. I want to use dill.dumps and dill.loads to exchange data between my main program and these QProcesses. Here's where it gets strange: when I launch the process from the interface (the main program), the import of dill fails in the process (error: No module named 'dill')! HOWEVER, this same import works when launching the main program, which uses the same virtual environment and dependencies. The import also works perfectly fine when the process is launched directly from its Python file. Finally, if I replace dill with pickle in my imports and use pickle.dumps and pickle.loads, the imports don't pose any problems and the process runs perfectly even when launched from the interface. (so I don't think there's an issue with a different environment, missing dependencies, or code in launching the QProcess). I should mention that I'm on Windows. If anyone could help me understand, I would be very grateful.
I'm trying to pass arguments to my QProcess by launching it with the block:
@Slot()
def start_process(self):
process = QProcess()
process.readyReadStandardOutput.connect(self.handle_process_stdout)
process.readyReadStandardError.connect(self.handle_process_stderr)
process.finished.connect(self.handle_process_finished)
arg_to_serialize = {"Tracking_Process_sym" : self.starting_tracker.currentText(),
"Tracking_board_df" : Tracker.all_trackers[self.starting_tracker.currentText()].tracking_board_df}
arguments = dill.dumps(arg_to_serialize)
encoded_arg = base64.b64encode(arguments).decode('utf-8')
process.setProgram(r"C:\Python312\python.exe")
process.setArguments([r'testdiil.py', encoded_arg])
process.setProcessChannelMode(QProcess.MergedChannels)
process.start()
self.processes_list.append(process)
Everything works fine with pickle.dumps(arg_to_serialize) but not with dill.dumps(arg_to_serialize). And "I'm encountering the same issue even when I pass no arguments and launch a simple test QProcess like this:
import base64
import sys
import asyncio
try:
import dill
except Exception as e:
print(f'Import failed because {e}')
# Object to serialize
data = {'a': 42, 'b': [1, 2, 3], 'c': {'x': 10, 'y': 20}}
# Serialization of the object with Dill
serialized_data = dill.dumps(data)
# Encoding in base64 for transfer as a command-line argument
encoded_data = base64.b64encode(serialized_data).decode('utf-8')
# Decoding from base64 to retrieve serialized data
decoded_data = base64.b64decode(encoded_data)
# Deserialization of the object with Dill
deserialized_data = dill.loads(decoded_data)
# Printing the deserialized object
print(deserialized_data)
Upvotes: 0
Views: 251