Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:20:07+00:00 2026-05-23T10:20:07+00:00

I’m having a funny issue with map_async that i can’t figure out. I’m using

  • 0

I’m having a funny issue with map_async that i can’t figure out.

I’m using python’s multiprocessing library with process pools. I’m trying to pass a list of strings to compare against and a list of strings to be compared to a function using map_async()

right now i have:

from multiprocessing import Pool, cpu_count
import functools

dictionary = /a/file/on/my/disk
passin = /another/file/on/my/disk

num_proc = cpu_count()

dictionary = readFiletoList(fdict)
dictionary = sortByLength(dictionary)

words = readFiletoList(passin, 'WINDOWS-1252')
words = sortByLength(words)

result = pool.map_async(functools.partial(mpmine, dictionary=dictionary), [words], 1000)

def readFiletoList(fname, fencode='utf-8'):
  linelist = list()
  with open(fname, encoding=fencode) as f:
    for line in f:
      linelist.append(line.strip())
  return linelist


def sortByLength(words):
  '''Takes an ordered iterable and sorts it based on word length'''
  return sorted(words, key=len)

def mpmine(word, dictionary):
  '''Takes a tuple of length 2 with it's arguments.

  At least dictionary needs to be sorted by word length. If not, whacky results ensue.
  '''
  results = dict()
  for pw in word:
    pwlen = len(pw)
    pwres = list()
    for word in dictionary:
      if len(word) > pwlen:
        break
      if word in pw:
        pwres.append(word)
    if len(pwres) > 0:
      results[pw] = pwres
  return results



if __name__ == '__main__':
  main()

Both dictionary and words are lists of strings. This results in only one process being used instead of the amount I have set. If i take the square brackets off the variable ‘words’ it seems to iterate through each string’s characters in turn and cause a mess.

What i would like to have happen is it take like 1000 strings out of words and pass them into the worker process and then get the results, because this is a ridiculously parallelisable task.

EDIT: Added more code to make what’s going on more clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:20:07+00:00Added an answer on May 23, 2026 at 10:20 am

    Ok, i actually figured this one out myself. I’m only going to post the answer here for anyone else who might come along and have the same issue. The reason i was having problems was because map_async takes one item from the list (in this case a string), and feeds it into the function, which was expecting a list of strings. so it then was treating each string as a list of chars basically. the corrected code for mpmine is:

    def mpmine(word, dictionary):
      '''Takes a tuple of length 2 with it's arguments.
    
      At least dictionary needs to be sorted by word length. If not, whacky results ensue.
      '''
      results = dict()
      pw = word
      pwlen = len(pw)
      pwres = list()
      for word in dictionary:
        if len(word) > pwlen:
          break
        if word in pw:
          pwres.append(word)
      if len(pwres) > 0:
        results[pw] = pwres
      return results
    

    I hope this helps anyone else facing a similar issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Does anyone know how can I replace this 2 symbol below from the string
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.