I was trying to use Process to create threads in python.
But it keeps showing errors.
And here is my code:
from multiprocessing import Process
import threading
class OneProcess(Process):
def __init__(self):
super().__init__()
self.workers = []
for i in range(5):
worker = OneThread()
self.workers.append(worker)
def run(self):
for worker in self.workers:
worker.start()
for worker in self.workers:
worker.join()
class OneThread(threading.Thread):
def __init__(self):
super().__init__()
def run(self):
print("do somethings")
class Shell():
def __init__(self):
self.first_process = OneProcess()
def start(self):
self.first_process.start()
if __name__ == "__main__":
shell = Shell()
shell.start()
And here is the error:
ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects
I guess it just can't serilize the thread object? So is there any method can achieve this? Or using Process to create threads is unavaliable in python?