Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please document one user error pattern #60

Closed
marxin opened this issue Apr 15, 2020 · 2 comments
Closed

Please document one user error pattern #60

marxin opened this issue Apr 15, 2020 · 2 comments

Comments

@marxin
Copy link
Contributor

marxin commented Apr 15, 2020

It took me more than hour to realize what's wrong:

#!/usr/bin/env python3

from pebble import ProcessPool

class Tester:
    def __init__(self):
        self.futures = []

    def run_one(self, v):
        time.sleep(1)

    def run(self):
        while True:
            print('new ProcessPool')
            with ProcessPool(max_workers=16) as pool:
                f = pool.schedule(self.run_one, [1])
                self.futures.append(f)
                f.result()

Tester().run()
$ ./sample.py
new ProcessPool
Traceback (most recent call last):
  File "/tmp/pe.py", line 20, in <module>
    Tester().run()
  File "/tmp/pe.py", line 18, in run
    f.result()
  File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/lib/python3.8/site-packages/pebble/pool/process.py", line 204, in schedule
    self.worker_manager.dispatch(task)
  File "/usr/lib/python3.8/site-packages/pebble/pool/process.py", line 335, in dispatch
    raise error
  File "/usr/lib/python3.8/site-packages/pebble/pool/process.py", line 333, in dispatch
    self.pool_channel.send(WorkerTask(task.id, task.payload))
  File "/usr/lib/python3.8/site-packages/pebble/pool/channel.py", line 66, in send
    return self.writer.send(obj)
  File "/usr/lib64/python3.8/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/usr/lib64/python3.8/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
TypeError: cannot pickle '_thread.RLock' object

The problem is that pickle is called for my Tester which contains a reference to pebble.ProcessFuture.

@noxdafox
Copy link
Owner

@marxin
Copy link
Contributor Author

marxin commented Apr 15, 2020

What a noobish mistake I made, thank you for the links!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants