Coder Social home page Coder Social logo

Support Python 3.8 onwards about amptk HOT 3 CLOSED

peterjc avatar peterjc commented on August 20, 2024
Support Python 3.8 onwards

from amptk.

Comments (3)

nextgenusfs avatar nextgenusfs commented on August 20, 2024

Multiprocessing appears to have changed in py3.8 -- I didn't have time to diagnose/fix the problem so pinned to <3.8. I will try to find time to fix, but essentially how I'm using multiprocessing fails in v3.8:

def runMultiProgress(function, inputList, cpus, args=False):
    #setup pool
    p = multiprocessing.Pool(cpus)
    #setup results and split over cpus
    tasks = len(inputList)
    results = []
    for i in inputList:
        results.append(p.apply_async(function, args=([i]), kwds={'args':args}))
    #refresh pbar every 5 seconds
    while True:
        incomplete_count = sum(1 for x in results if not x.ready())
        if incomplete_count == 0:
            break
        sys.stdout.write("     Progress: %.2f%% \r" % (float(tasks - incomplete_count) / tasks * 100))
        sys.stdout.flush()
        time.sleep(1)
    p.close()
    p.join()

from amptk.

nextgenusfs avatar nextgenusfs commented on August 20, 2024

Okay a little digging suggests that in py3.8 the default method changed for multiprocessing https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods.

So it seems to keep this working I just needed to explicitly define the start method, ie

def runMultiProgress(function, inputList, cpus, args=False):
    #setup pool
    ctx = multiprocessing.get_context('fork')
    p = ctx.Pool(cpus)
    #setup results and split over cpus
    tasks = len(inputList)
    results = []
    for i in inputList:
        results.append(p.apply_async(function, args=([i]), kwds={'args':args}))
    #refresh pbar every 5 seconds
    while True:
        incomplete_count = sum(1 for x in results if not x.ready())
        if incomplete_count == 0:
            break
        sys.stdout.write("     Progress: %.2f%% \r" % (float(tasks - incomplete_count) / tasks * 100))
        sys.stdout.flush()
        time.sleep(1)
    p.close()
    p.join()

from amptk.

peterjc avatar peterjc commented on August 20, 2024

So should be fixed by 285c3b4 and the release of v1.5.3 👍

from amptk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.