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

  • Home
  • SEARCH
  • 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 6720235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:11:18+00:00 2026-05-26T09:11:18+00:00

I’m getting an weird error using queues/multiprocessing. I basically have a function that takes

  • 0

I’m getting an weird error using queues/multiprocessing. I basically have a function that takes a list then parses it.

I have to do this many times so I thought it would be a good idea to spread it over the cores I have and I tried to setup a queue but its not working. Here’s my code:

# Establish communication queues
tasks = multiprocessing.Queue()

# Start consumers
num_consumers = multiprocessing.cpu_count() * 2
print 'Creating %d consumers' % num_consumers
worker = [ rules(tasks)
          for i in xrange(num_consumers) ]
for w in consumers:
    w.start()


def loadGraph(dayCurrent, day2Previous):



for dayCurrentCount  in graph[dayCurrent]:
    dayCurrentValue = graph[dayCurrent][dayCurrentCount]
    for day1Count  in graph[day2Previous]:
        day1Value = graph[day2Previous][day1Count]
        rulesDataToPass = [day1Count, day1Value, dayCurrentCount, dayCurrentValue, dayCurrent, day2Previous]

        tasks.put(rulesDataToPass)



tasks.close()
tasks.join_thread()

I’m not sure what I’m doing wrong. Without using a queue it works fine. The problem is my function requires multiple variables to run(before I was sending it individually but decided to bunch it all together as a list so I can queue it up).

please help!

Thanks in advance!

UPDATE: as requested, here is the traceback:

Traceback (most recent call last):
  File "/Users/lostsoul/Dropbox/code/learning/python/game.py", line 213, in <module>
    for i in xrange(num_consumers) ]
  File "Users/lostsoul/Dropbox/code/learning/python/game.py", line 191, in rules
    day1Count = dict[0]
TypeError: 'Queue' object does not support indexing

basically I have sending the data to a function I have called ‘rules’, the dict is then parsed like day1Count = dict[0],..day1value dict[1]…etc.. I am basically trying to compare two dictionaries against each other. so the queue is from a nested for loop that pairs every entry together(adding it to the queue which I’m hoping will get processed on all my cpu’s..it works right now individually but takes 15 min using one cpu).

UPDATE2: Here is the rules function. Its simple. basically takes the values, and then passes them to other functions(its my version of a rules engine)

def rules(dict):
    day1Count = dict[0]
    day1Value = dict[1]
    dayCurrentCount = dict[2] 
    dayCurrentValue = dict[3] 
    dayCurrent = dict[4] 
    day2Previous = dict[5]
    exactSame(day1Count, day1Value, dayCurrentCount, dayCurrentValue, dayCurrent, day2Previous)
    withinFivePercentChange(day1Count, day1Value, dayCurrentCount, dayCurrentValue, dayCurrent, day2Previous)
    deleteNonEdgeNodes(dayCurrentCount, dayCurrentValue, dayCurrent)

Without queue this works fine.

  • 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-26T09:11:19+00:00Added an answer on May 26, 2026 at 9:11 am

    This line TypeError: 'Queue' object does not support indexing is indicating that your dict variable is of type Queue (which you probably dont want it to be). Double check lines 191 and up to make sure you are properly assigning the dict variable properly.


    Also, NEVER use a type name as a variable name. dict is a type, you shouldn’t use it as the name for a dictionary variable. Use my_dict or something similar. Its possible that by using dict as a variable name, your setting some other variable to a dict object, instead of assigning it the value of the dict variable.

    See stdtypes for more info on the dict class.


    Heres the problem, your sending tasks which is a Queue to rules(), which is expecting an iterable type (list):

    tasks = multiprocessing.Queue()
    worker = [rules(tasks) for i in xrange(num_consumers)]
    
    def rules(dict):
        day1Count = dict[0]
        day1Value = dict[1]
        dayCurrentCount = dict[2] 
        dayCurrentValue = dict[3] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.