Python multiprocessing: Share data from dynamically created module on windows - python

I'd like to send data defined in a module that was dynamically loaded with imp via a Manager().Queue() on Windows. Is this possible? Here is a minimal testcase to demonstrate what I mean:
import imp
import sys
from multiprocessing import Manager
if __name__ == '__main__':
s = """
def payload():
print("It works!")
"""
mod = imp.new_module('testcase')
exec s in mod.__dict__
sys.modules['testcase'] = mod
payload = mod.payload
payload() # It works!
m = Manager()
queue = m.Queue()
queue.put(payload) # AttributeError: 'module' object has no attribute 'payload'
Note: The use of imp.new_module + exec is just to get the testcase in a single file. The same AttributeError is raised when using imp.load_source.
Note2: This testcase leaves out all the Pool/worker code as the error happens before then.
Here is the output with full traceback from running the above script:
It works!
Traceback (most recent call last):
File "testcase.py", line 23, in <module>
queue.put(payload) # AttributeError: 'module' object has no attribute 'payload'
File "<string>", line 2, in put
File "c:\Users\Andrew\dev\python\lib\multiprocessing\managers.py", line 774, in _callmethod
raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError:
---------------------------------------------------------------------------
Traceback (most recent call last):
File "c:\Users\Andrew\dev\python\lib\multiprocessing\managers.py", line 240, in serve_client
request = recv()
AttributeError: 'module' object has no attribute 'payload'
---------------------------------------------------------------------------
Thanks!

Related

Influxdb deployment on raspberry pi: AttributeError: 'InfluxDBClient' object has no attribute 'api_client'

I am experiencing issues to instantiate an Influxdb client for python in a Raspberry Pi 4b (OS: Linux).
influxdb_client version: 1.35
I have tested to pass the arguments by means of a yaml file as well as directly to the InfluxDBClient class:
Option 1:
self.url = config["INFLUXDB_URL"]
self.org = config["INFLUXDB_ORG"]
self.token = config["INFLUXDB_TOKEN"]
self.influxClient = InfluxDBClient(url=self.url, token=self.token, org=self.org, debug=True)
Option 2:
self.influxClient = InfluxDBClient(url="https://TEST.data.test.ca/", token="TOKENVALUE", org="JPerez")
And voila the result:
Exception ignored in: <function ApiClient.__del__ at 0x7f641ecee0>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/influxdb_client/_sync/api_client.py", line 84, in __del__
self._signout()
File "/usr/local/lib/python3.8/site-packages/influxdb_client/_sync/api_client.py", line 661, in _signout
if _requires_expire_user_session(self.configuration, self.cookie):
AttributeError: 'ApiClient' object has no attribute 'configuration'
Exception ignored in: <function InfluxDBClient.__del__ at 0x7f648d6c10>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/influxdb_client/client/influxdb_client.py", line 283, in __del__
if self.api_client:
AttributeError: 'InfluxDBClient' object has no attribute 'api_client'

Unable to create owl:NamedIndividual on owlready2

I need to create a NamedIndividual (https://www.w3.org/TR/owl2-syntax/#Named_Individuals) but I am not seeing a way to do it.
The following example:
from owlready2 import *
onto = get_ontology("example")
class NamedIndividual(Thing): namespace = owl
print(NamedIndividual.iri)
print(NamedIndividual.name)
mini = NamedIndividual()
onto.save("minrep.rdf")
Gives the following error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual("example")
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 137, in __init__
if self.storid > 0: self.namespace.ontology._add_obj_triple_spo(self.storid, rdf_type, owl_named_individual)
TypeError: '>' not supported between instances of 'str' and 'int'
If I instantiate the class without a name, I get another error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual()
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 123, in __init__
iri = self.namespace.world._new_numbered_iri("%s%s" % (self.namespace._base_iri, self.generate_default_name()))
AttributeError: 'World' object has no attribute '_new_numbered_iri'
Any ideas on what is happening there? Thanks!

AttributeError: 'Namespace' object has no attribute 'out_dir'

I am trying to run a python script to download(ScanNet data) but this error arises and I don't know what to do !
Error message:
C:\Users\youss>python download-scannet.py --out_dir C:\Users\youss\scannet --tf_semantic
By pressing any key to continue you confirm that you have agreed to the ScanNet terms of use as described
a
Traceback (most recent call last):
File "C:\Users\youss\download-scannet.py", line 232, in <module>
if __name__ == "__main__": main()
File "C:\Users\youss\download-scannet.py", line 160, in main
out_dir_scans = os.path.join(args.out_dir, 'scans')
AttributeError: 'Namespace' object has no attribute 'out_dir'
lines 160,161,162:
out_dir_scans = os.path.join(args.out_dir, 'scans')
out_dir_test_scans = os.path.join(args.out_dir, 'scans_test')
out_dir_tasks = os.path.join(args.out_dir, 'tasks')
I am using urllib.request

Define method from external module (Python)

I'm trying to define a method (let's call it hello) in main.py's Things class, from define.py.
The code I currently have is raising AttributeError: module 'runme' has no attribute 'promptMe' (full traceback below).
Here's main.py's code:
import define
class Things:
def doWhatever():
print("whatever")
Here's define.py's code:
import main
def hello():
print("Hello!")
main.Things.hello = hello()
I've tried other solutions such as def main.Things.hello: hello() and def main.Things.hello: print("Hello!") but none work.
Here's the traceback when running define.py:
Traceback (most recent call last):
File "define.py", line 5, in <module>
import main
File "/path/to/main.py", line 9, in <module>
import define
File "/path/to/define.py", line 10, in <module>
main.Things.hello = hello
AttributeError: module 'main' has no attribute 'Things'
All help would be greatly appreciated. Thanks!

Python error : AttributeError: 'module' object has no attribute 'heappush'

I am trying some simple programs which involve multiprocessing features in Python.
The code is given below:
from multiprocessing import Process, Queue
def print_square(i):
print i*i
if __name__ == '__main__':
output = Queue()
processes = [Process(target=print_square,args=(i,)) for i in range(5)]
for p in processes:
p.start()
for p in processes:
p.join()
However, this gives an error message AttributeError: 'module' object has no attribute 'heappush'. The complete output upon executing the script is given below:
Traceback (most recent call last):
File "parallel_3.py", line 15, in
output = Queue()
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\__init__.py", line 217, in Queue
from multiprocessing.queues import Queue
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\queues.py", line 45, in
from Queue import Empty, Full
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 212, in
class PriorityQueue(Queue):
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 224, in PriorityQueue
def _put(self, item, heappush=heapq.heappush):
AttributeError: 'module' object has no attribute 'heappush'
The code compiles fine if the output=Queue() statement is commented.
What could be possibly causing this error ?
Your filename should be the package name. Change to another filename such as heap and it will work.

Categories

Resources