Multi-threaded programs to update Python packages in bulk

Asked 2 years ago, Updated 2 years ago, 15 views

I would like to update all packages in one package using threads in Python.
However, the code below doesn't get as fast as the Go routine or when multi-threaded with Python.Why is it getting late?

    
#!/usr/local/bin/python 3.4
import subprocess
importos
import threading
import re


default(package_name):
    os.system("pipe 3.4 install" + package_name + "-U")

s=subprocess.check_output(["pip3.4", "freeze"]).decode()
package_list=re.findall(".+(?===)",s)
package_list.extend(["pip", "setuptools")
print(package_list)

for vin package_list:
    threading.Thread(target=update, args=(v,)) .start()

    

python

2022-09-29 22:19

1 Answers

This is not the answer, but if you run the following code for Python's GIL, for example,

 from threading import thread
importos

def sleep(n):
  os.system("date; echo"+str(n)+";sleep1")

for n in range (0, 10):
  Thread(target=sleep, args=(n,)) .start()

The results are as follows:

Fri Mar 6 22:30:35 JST 2015
0
Fri Mar 6 22:30:35 JST 2015
1
Fri Mar 6 22:30:35 JST 2015
Fri Mar 6 22:30:35 JST 2015
3
4
Fri Mar 6 22:30:35 JST 2015
Fri Mar 6 22:30:35 JST 2015
5
2
Fri Mar 6 22:30:35 JST 2015
7
Fri Mar 6 22:30:35 JST 2015
8
Fri Mar 6 22:30:35 JST 2015
6
Fri Mar 6 22:30:35 JST 2015
9

Apparently, os.system() will remove the GIL.

Message 103280-Python tracker

It locks the buffer causes.system() releases the GIL when calling system().


2022-09-29 22:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.