Right flow organization



  • I don't know very much about Python, so I need a man's advice that can tell me the most productive and the most appropriate way to organize fluxes.

    Like I did before. For example, I have a posting function...

    def http_request():
       #тело функции
    

    class HTTPThread(threading.Thread):
    def run(self):
    try:
    http_request()
    except Exception, ex:
    pass

    for i in range(5):
    while True:
    t = HTTPThread()
    t.start()

    What is the correct or wrong way of achieving multi-points?



  • Simple compact example of multi-potentity use for HTTP queries https://stackoverflow.com/a/2846697/5485944 😞

    import Queue
    import threading
    import urllib2
    

    def get_url(q, url):
    q.put(urllib2.urlopen(url).read())

    urls = ["http://google.com", "http://yahoo.com"]

    q = Queue.Queue()

    for u in urls:
    t = threading.Thread(target=get_url, args=(q, u))
    t.daemon = True
    t.start()

    s = q.get()
    print s

    Work has been illustrated here on the queues, which has resulted in the return of the calculations from the generating flows to the main flow. Without the use of one of the synchronization mechanisms, the correct return would not be possible. The worms are perfect for that.

    It is worth adding that Python ' s multi-point ensures that only the tasks expected to be completed are effectively evaporated (as in the case of anticipation of the HTTP request). For computing tasks with a centralized processor load, there is no real evaporation of the load between flows due to the availability of https://wiki.python.org/moin/GlobalInterpreterLock ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2