Experimenting multiprocessing with multi Threads requesting to the url in python.


Finally i got all the url html responce correctly it is working fine as expected.With multiprocessing and multi Threads.



main.py

def calc_square(number):
   time.sleep(3)
   print('Square:' , number * number)
   result = number * number
   print(os.getpid())

print(result)

def calc_quad(number):
   print(os.getpid())

print('Quad:' , number * number * number * number)


def test1():
    print(os.getpid())
    print('test1 :' ,)

def test2():
    print(os.getpid())
    print('test2 :' ,)

def test3():
    print(os.getpid())
    print('test3 :' ,)

if __name__ == '__main__':


   number = 7
   start = time.time()
   result = None

   # p1 = multiprocessing.Process(target=calc_square, args=(number,))
   # p2 = multiprocessing.Process(target=calc_quad, args=(number,))
     p3 = multiprocessing.Process(target=run_test1)
     p4 = multiprocessing.Process(target=run_test)
     p5 = multiprocessing.Process(target=test3)


    # p1.start()
    # p2.start()
    p3.start()
    p4.start()
     p5.start()

    # p1.join()
   # p2.join()
    p3.join()
    p4.join()
    p5.join()

   end = time.time()
   print(f'Time taken {end - start}')
test.py
import os
import time

from Utility.NetworkRequest import getHtml_Str_From_Url
from Utility.Utility import create_thread

link_list = ['https://tutorialedge.net/python/concurrency/python-threadpoolexecutor- 
  tutorial/'
       , 'https://www.machinelearningplus.com/python/parallel-processing-python/']

def run_test():

  # count = 0

  thread = create_thread(run_other)
  thread.start()
  print(hash(thread))


def run_other():
   count = 0

  while len(link_list) > count:
      print("from test")
      print("process id:- " + str(os.getpid()))
      print("links: - " + str(link_list[count]))
      getHtml = getHtml_Str_From_Url(link_list[count])
      print(getHtml)
      count += 1
save.py
import os
import time

from Utility.NetworkRequest import getHtml_Str_From_Url
from Utility.Utility import create_thread

 link_list = ['https://realpython.com/intro-to-python- 
   threading/','https://pymotw.com/3/concurrent.futures/']

def run_test1():

   thread = create_thread(run_other)
   thread.start()
   print(hash(thread))

def run_other():
    count = 0

    while len(link_list) > count:
        print("from save")
        print("process id:- " + str(os.getpid()))
        print("links: - " + str(link_list[count]))
        getHtml = getHtml_Str_From_Url(link_list[count])
        print(getHtml)
        count += 1

Comments

Popular posts from this blog

Error:java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240) at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215) at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143) at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78) at com.google.android.material.chip.ChipDrawable.loadFromAttributes(ChipDrawable.java:359) at com.google.android.material.chip.ChipDrawable.createFromAttributes(ChipDrawable.java:292) at com.google.android.material.chip.Chip.(Chip.java:193) at com.google.android.material.chip.Chip.(Chip.java:186) at com.google.android.material.chip.Chip.(Chip.java:182) at com.demo.nspl.restaurantlite.Navigation_Drawer.SalesFragment.getFilterChip(SalesFragment.java:158) at com.demo.nspl.restaurantlite.Navigation_Drawer.SalesFragment.lambda$onCreateView$0(SalesFragment.java:71) at com.demo.nspl.restaurantlite.Navigation_Drawer.-$$Lambda$SalesFragment$KCm-iiczjdYbpiNmaNw12gtFOoQ.onClick(lambda) at android.view.View.performClick(View.java:5268) at android.view.View$PerformClick.run(View.java:21550) at android.os.Handler.handleCallback(Handler.java:822) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5811) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)

Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html