Question
The paper code encountered a problem similar to the following. After some efforts, it can be regarded as solving this problem.
# import torch
# # print(torch.__version__)
# # print(torch.cuda.is_available())
import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(xs):
t = temp_num[xs[0]] * 2
return t
def a():
global temp_num
temp_num = [4, 5, 6]
pool = multiprocessing.Pool(cores)
xs = range(3)
batch_result = pool.map(b,xs)
print(batch_result)
def main():
a()
if __name__ == '__main__':
main()
Error:
solve
import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(x):
xs = x[0]
temp_num = x[1]
t = temp_num[xs] * 2
return t
def a():
global temp_num
temp_num = [4, 5, 6]
pool = multiprocessing.Pool(cores)
xs = range(3)
z =zip(xs,[temp_num] * 3)
result = pool.map(b,z)
print(result)
def main():
a()
if __name__ == '__main__':
main()
Read More:
- [How to Fix] NameError: name ‘requests‘ is not defined & NameError: name ‘request‘ is not defined
- pyspark : NameError: name ‘spark’ is not defined
- [NLP] NameError in using nltk: name ‘freqdist’ is not defined
- Solving the problem of NameError: name ‘reload’ is not defined
- Django project running service reported an error NameError: name ‘OS’ is not defined
- Multithreading: when doing unit test, use thread pool to find that the specified code is not running and skip directly
- Uncaught ReferenceError: FileAsyncWriter is not defined
- An error is reported when passing data pages using Ajax: Vue is not defined
- Vue project, browser error: referenceerror: H is not defined
- python3 Error in sitecustomize; set PYTHONVERBOSE for traceback: NameError: name ‘modules_list’ …
- JS error: require is not defined
- Reference error: ecarts is not defined
- Applet error – referenceerror: regeneratorruntime is not defined
- Error reported by gulp: referenceerror: primordials is not defined
- Property xxx was accessed during render but is not defined on instance
- Eslint error handling: ‘QQ’ is not defined
- Error reported using layui $is not defined
- VBA “user defined type not defined” MSXML2.DOMDocument
- Error in v-on handler: “ReferenceError: XXX is not defined“
- Uniapp ESLint error: ‘uni‘ is not defined no-undef [How to Solve]