0

I have a couple of custom modules present in the Modules directory of the web2py. These modules are easily imported to the controller file. But when I am trying to import these modules in the scheduler.py file I am getting the error. Kindly help.

/home/www-data/web2py$ python web2py.py -K <app_name>
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2018
Version 2.15.4-stable+timestamp.2017.09.02.04.02.22
Database drivers available: sqlite3, imaplib, pymysql, pg8000
starting scheduler for "<app_name>"...
Currently running 1 scheduler processes
Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "applications/<app_name>/models/scheduler.py", line 28, in <module>
    customSSH = local_import('customSSH')
  File "/home/www-data/web2py/gluon/compileapp.py", line 444, in <lambda>
    local_import_aux(name, reload, app)
  File "/home/www-data/web2py/gluon/compileapp.py", line 347, in local_import_aux
    module = __import__(name)
  File "/home/www-data/web2py/gluon/custom_import.py", line 111, in custom_importer
    return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
  File "applications/<app_name>/modules/customSSH.py", line 4, in <module>
    import multiprocessing
  File "/home/www-data/web2py/gluon/custom_import.py", line 111, in custom_importer
    return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
  File "applications/<app_name>/modules/multiprocessing/__init__.py", line 64, in <module>
    import multiprocessing.patch
  File "/home/www-data/web2py/gluon/custom_import.py", line 111, in custom_importer
    return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
ImportError: No module named patch
May
  • 1,158
  • 2
  • 13
  • 24
  • 1
    Note, `local_import` was deprecated a few years ago. There is no need for it -- just use `import customSSH`. – Anthony Jul 20 '18 at 14:55
  • Also, are you using `python-multiprocessing`? If so, what version of Python are you on? – Anthony Jul 20 '18 at 14:56
  • I am on python2.7 – May Jul 20 '18 at 17:22
  • If you are using `python-multiprocessing`, I don't think you should need it with Python 2.7 (it was intended to backport functionality to older versions of Python). – Anthony Jul 20 '18 at 23:04

1 Answers1

2

The problem is that multiprocessing is also the name of a module in the Python standard library. The initial import of multiprocessing is found in /modules by the web2py custom importer. However, when multiprocessing itself attempts to import multiprocessing.patch, the native Python importer expects the .patch to be a submodule of the standard library multiprocessing, which of course fails.

If multiprocessing is a third-party library, it would probably be better to install it outside of the application's /modules folder. If it is a custom module or a module you are comfortable editing, you can either rename the module or change the imports to refer to the full applications.<app_name>.modules path -- for example:

import applications.<app_name>.modules.multiprocessing.patch as patch
Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Thank you Anthony. Removing multiprocessing module from web2py's module worked. Thank you so much for your time on it. – May Jul 20 '18 at 17:23