Note that there are some explanatory texts on larger screens.

plurals
  1. POSyntax issue with python dictionary and multiprocessing script
    primarykey
    data
    text
    <p>Hi I am trying to be able to start a thread from a dictionary entry using this code below. The rest of the code in the script is known good and fully functional. I cam gonna have to be able to choose from a bunch of different subroutines so I want to remove as much boilerplate as possible from the code. Thanks guys and gals!!!!</p> <pre><code>class worker_manager: i = test_imports() template('one': i.import_1, 'two': i.import_2); def __init__(self): self.children = {} def generate(self, control_Queue, threadName, runNum): p = multiprocessing.Process(target=self.template[threadName], args=(control_Queue, runNum)) self.children[threadName] = p p.start() def terminate(self, threadName): self.children[threadName].join </code></pre> <p>When I run this code I get this error:</p> <pre><code> File "dynamicTest1.py", line 53 template('one': i.import_1, 'two': i.import_2); ^ SyntaxError: invalid syntax </code></pre> <p>Anyone have any advice? </p> <p>EDIT: Here is how a normal thread works:</p> <pre><code>def generate(self, control_Queue, threadName, runNum): i = test_imports() if threadName == 'one': print ("Starting import_1 number %d") % runNum p = multiprocessing.Process(target=i.import_1, args=(control_Queue, runNum)) self.children[threadName] = p p.start() </code></pre> <p>I wanna replace target in <code>p = multiprocessing.Process(target=i.import_1, args=(control_Queue, runNum))</code> with a dictionary to remove the need for what was a MASSIVE amount of if/elif/else statements.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload