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

Remote object type error #361

Open
WqyJh opened this issue Nov 29, 2019 · 0 comments
Open

Remote object type error #361

WqyJh opened this issue Nov 29, 2019 · 0 comments
Assignees
Labels
To Start Description reviewed and a maintainer needs "to start" triage

Comments

@WqyJh
Copy link

WqyJh commented Nov 29, 2019

I'm using apscheduler with rpyc, the service expose two of scheduler's method.
remove_job works perfectly but add_job crashed.

class SchedulerService(rpyc.Service):
    def exposed_add_job(self, *args, **kwargs):
        return self.scheduler.add_job(*args, **kwargs)

    def exposed_remove_job(self, job_id, jobstore=None):
        return self.scheduler.remove_job(job_id, jobstore=jobstore)

My local call is as follows:

        scheduler.remove_job(job_id)

        _trigger = CronTrigger.from_crontab(mirror.sync_time)
        scheduler.add_job(sync_mirror, trigger=_trigger,
                          id=job_id,
                          args=(mirror,))

This is the remote traceback: the _create_trigger method in the apscheduler failed.

========= Remote Traceback (1) =========
Traceback (most recent call last):
  File "/home/linux/venv/mirrorit-qbPURi0Y/lib/python3.6/site-packages/rpyc/core/protocol.py", line 323, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File "/home/linux/venv/mirrorit-qbPURi0Y/lib/python3.6/site-packages/rpyc/core/protocol.py", line 585, in _handle_call
    return obj(*args, **dict(kwargs))
  File "/home/linux/Works/PyCharmProjects/mirrorit/mirrorit/scheduler.py", line 42, in exposed_add_job
    return self.scheduler.add_job(*args, **kwargs)
  File "/home/linux/venv/mirrorit-qbPURi0Y/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 420, in add_job
    'trigger': self._create_trigger(trigger, trigger_args),
  File "/home/linux/venv/mirrorit-qbPURi0Y/lib/python3.6/site-packages/apscheduler/schedulers/base.py", line 915, in _create_trigger
    trigger.__class__.__name__)
TypeError: Expected a trigger instance or string, got ABCMeta instead

As we can see from the source code of _create_trigger, it determines whether the trigger is an instance of BaseTrigger. The _trigger variable created by CronTrigger.from_crontab(mirror.sync_time) is an instance of class CronTrigger(BaseTrigger), therefore it's indeed an instance of BaseTrigger. However, the server end resolved this argument to an instance of ABCMeta which cause the exception. Actually, BaseTrigger is a subclass of ABCMeta (class BaseTrigger(six.with_metaclass(ABCMeta))).

    def _create_trigger(self, trigger, trigger_args):
        if isinstance(trigger, BaseTrigger):
            return trigger
        elif trigger is None:
            trigger = 'date'
        elif not isinstance(trigger, six.string_types):
            raise TypeError('Expected a trigger instance or string, got %s instead' %
                            trigger.__class__.__name__)

        # Use the scheduler's time zone if nothing else is specified
        trigger_args.setdefault('timezone', self.timezone)

        # Instantiate the trigger class
        return self._create_plugin_instance('trigger', trigger, trigger_args)

Therefore, I think the remote object type should be the base class type rather than the top level super class type.

Environment
  • rpyc version: 4.1.2
  • python version: 3.6.5
  • operating system: Deepin 15.11
@comrumino comrumino self-assigned this Dec 3, 2019
@comrumino comrumino added the To Start Description reviewed and a maintainer needs "to start" triage label Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
To Start Description reviewed and a maintainer needs "to start" triage
Projects
None yet
Development

No branches or pull requests

2 participants