First time here? Check out the FAQ!

Ask Your Question
1

Pickling error with multiprocessing

asked 0 years ago

mn124700 gravatar image

Good morning all. I'm trying to run a test example of multiprocessing in SageMath 10.3 on Jupyter. I get an error saying that the lookup for the function "task" failed. I'm a bit new to this, and am wondering where I'm going wrong. Is there a package I forgot to install or something? Thanks. Eric

reset()
from random import random
from time import sleep
from multiprocessing.pool import Pool


def task(identifier):
    # generate a value
    value = random()
    # report a message
    print(f'Task {identifier} executing with {value}', flush=True)
    # block for a moment
    sleep(value)
    # return the generated value
    return value

def eric():
    # create and configure the process pool
    with Pool() as pool:
        # execute tasks in order, process results out of order
        for result in pool.imap_unordered(task, range(50)):
            print(f'Got result: {result}', flush=True)

eric()

PicklingError: Can't pickle <function task="" at="" 0x15676bc40="">: attribute lookup task on sage.all_cmdline failed

Preview: (hide)

Comments

Your code works fine in Sagecell

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

How do you run your code?

vdelecroix gravatar imagevdelecroix ( 0 years ago )
1

In doing a bit more research, I found that the pickling problem is with the "multiprocessing" package in Sage. This does not work on MacOS. An improved package, called "multiprocess", is available. I've installed this in my python environment, but can't seem to access it from Sage. As I understand things, Sage uses it's own python, and does not recognize the newly installed multiprocess.

Question: how do I import multiprocess into SageMath? I tried the command (from Jupyter running Sage 10.3):

pip install multiprocess

but this gives a syntax error at the word "install"

Thanks for any guidance Eric

mn124700 gravatar imagemn124700 ( 0 years ago )

I run it on OSX from Anaconda Navigator. From there I launch JupyterLab and select the SageMath 10.3 kernel for my notebook.

mn124700 gravatar imagemn124700 ( 0 years ago )

Have you tried to use built-in Sage's parallel computing functionality? https://doc.sagemath.org/html/en/refe...

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 0 years ago

slelievre gravatar image

Addressing the question in your comment, rather than the original question.

Here is how to install the multiprocess package for SageMath's Python.

In a code cell of a Jupyter sheet running the SageMath kernel, type:

%pip install multiprocess

and run that cell.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 307 times

Last updated: Aug 11 '24