How Can I Use Fork() In Python3.3
how can i use fork() in Python3.3 **This is My code : Input: #!/usr/bin/env python import os def Child_process(): print('We are in Child_Process') print('My PID: %d'%os.ge
Solution 1:
os.fork
is only available in Unix-like system. You cannot use that in Windows.
os.fork()
Fork a child process. Return 0 in the child and the child’s process id in the parent. If an error occurs OSError is raised.
Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have known issues when using fork() from a thread.
Availability: Unix.
Solution 2:
Since os.fork
isn't available on your target, consider instead using the subprocess
module or even (batteries-not-included) envoy
.
These create a convenient abstraction around launching children.
Solution 3:
You should use the python's default multiprocessing
package. It works with both Linux and Windows.
from multiprocessing import Process, Array
defsplit_work_receiver(import_type, process_no, i, shared_arr):
creds= login()
if creds isnotNone:
process_submissions(browser, i, import_type, process_no, shared_arr)
else:
print("Failed login.")
returndefsplit_work(base_path, i, connection_url, database_name):
shared_arr = Array('i', range(0)) # Used to send data across processeses
processes = [
Process(target=split_work_receiver, args=("arg1", base_path, i, shared_arr)),
Process(target=split_work_receiver, args=("arg1", base_path, i, shared_arr)),
Process(target=split_work_receiver, args=("arg1", base_path, i, shared_arr))]
#Run processesfor p in processes:
p.start()
whileTrue:
sleep(600)
#Exit the completed processesfor p in processes:
print('Closed process: '+ str(p))
p.join()
Post a Comment for "How Can I Use Fork() In Python3.3"