pyres icon indicating copy to clipboard operation
pyres copied to clipboard

ImportError for classes enqueued from the same file they are defined in

Open lost-theory opened this issue 13 years ago • 2 comments

Got tripped up by this when first testing pyres:

https://gist.github.com/910835/a455b67f4b049535efea8ab2d5a8b1f5d8c2af40

If I try to execute this job I get an ImportError, because the worker can't import __main__.Adder:

Traceback (most recent call last):
  File ".../pyres/worker.py", line 201, in process
    return job.perform()
  File ".../pyres/job.py", line 56, in perform
    payload_class = self.safe_str_to_class(payload_class_str)
  File ".../pyres/__init__.py", line 49, in safe_str_to_class
    raise ImportError('')
ImportError

Some ideas:

  1. In the enqueue, detect __main__ in class names and raise an exception (and add this info to the docs)
  2. Resolve the correct name (using inspect? inspect.getmodulename(inspect.getfile(klass)) ?)
  3. Add an option to enqueue to specify the name of the class to import

lost-theory avatar Apr 08 '11 22:04 lost-theory

Oh I see there's an enqueue_from_string... ignore option 3.

lost-theory avatar Apr 08 '11 22:04 lost-theory

i'll see if I can write up a testcase for this, then work on a fix.

binarymatt avatar Apr 12 '11 15:04 binarymatt