DonDebonair/slack-machine

Error "can't pickle module objects" using redis storage and schedule

enver opened this issue · 4 comments

enver commented

I've created new project and scheduled couple of actions. Using memory storage everything works as expected, however when I switch to redis bot can't start due to:

Traceback (most recent call last):
  File "slack-bot/.py3/bin/slack-machine", line 10, in <module>
    sys.exit(main())
  File "slack-bot/.py3/lib/python3.7/site-packages/machine/bin/run.py", line 14, in main
    bot.run()
  File "slack-bot/.py3/lib/python3.7/site-packages/machine/core.py", line 195, in run
    Scheduler.get_instance().start()
  File "slack-bot/.py3/lib/python3.7/site-packages/apscheduler/schedulers/background.py", line 33, in start
    BaseScheduler.start(self, *args, **kwargs)
  File "slack-bot/.py3/lib/python3.7/site-packages/apscheduler/schedulers/base.py", line 162, in start
    self._real_add_job(job, jobstore_alias, replace_existing)
  File "slack-bot/.py3/lib/python3.7/site-packages/apscheduler/schedulers/base.py", line 867, in _real_add_job
    store.add_job(job)
  File "slack-bot/.py3/lib/python3.7/site-packages/apscheduler/jobstores/redis.py", line 82, in add_job
    self.pickle_protocol))
TypeError: can't pickle module objects

I'm sorry to hear you're having problems. But without seeing some code of your plugin(s), it's hard to see what's going wrong. Can you share the code of the scheduled actions?

I too, have this problem, and I can recreate it with almost an empty plugin and Redis selected as storage backend.

from machine.plugins.base import MachineBasePlugin
from machine.plugins.decorators import listen_to, respond_to, schedule

class MyFancyPlugin(MachineBasePlugin):

    @schedule(hour='7-16', minute='*/5')
    def do_stuff(self):
        pass

When starting slack-machine, it errors out with this error:

[2020-01-07 14:48:33][DEBUG] root server.py:connect_slack_websocket:196 | RTM connected
    ✓ Connected to Slack
Traceback (most recent call last):
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/bin/slack-machine", line 10, in <module>
    sys.exit(main())
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/machine/bin/run.py", line 14, in main
    bot.run()
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/machine/core.py", line 195, in run
    Scheduler.get_instance().start()
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/apscheduler/schedulers/background.py", line 33, in start
    BaseScheduler.start(self, *args, **kwargs)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 162, in start
    self._real_add_job(job, jobstore_alias, replace_existing)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 867, in _real_add_job
    store.add_job(job)
File "/Users/me/Library/Caches/pypoetry/virtualenvs/my-bot-KXQlIt-n-py3.8/lib/python3.8/site-packages/apscheduler/jobstores/redis.py", line 81, in add_job
    pipe.hset(self.jobs_key, job.id, pickle.dumps(job.__getstate__(),
TypeError: cannot pickle 'module' object

I think I have found the reason for the error above.

I'm importing yaml into local_settings.py and this isn't allowed as this will make local_settings.py unpicleable.

@enver Are you by any chance importing stuff in local_settings.py?

enver commented

@davidolrik Yes, I do. Thanks for the hint, I'll try it out.