Skip to content

Commit 467a958

Browse files
KangOlsle-odoo
authored andcommitted
[FIX] core: handle gevent on command line correctly
1 parent 630b4b1 commit 467a958

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

odoo/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
# Is the server running with gevent.
1010
import sys
1111
evented = False
12-
if sys.modules.get("gevent") is not None:
12+
if len(sys.argv) > 1 and sys.argv[1] == 'gevent':
13+
sys.argv.remove('gevent')
14+
import gevent.monkey
15+
gevent.monkey.patch_all()
16+
import psycogreen.gevent
17+
psycogreen.gevent.patch_psycopg()
1318
evented = True
1419

1520
# Is the server running in prefork mode (e.g. behind Gunicorn).

odoo/cli/command.py

+2
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ def main():
6262
if command in commands:
6363
o = commands[command]()
6464
o.run(args)
65+
else:
66+
sys.exit('Unknow command %r' % (command,))

odoo/service/server.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ def worker_spawn(self, klass, workers_registry):
443443

444444
def long_polling_spawn(self):
445445
nargs = stripped_sys_argv()
446-
cmd = os.path.join(os.path.dirname(nargs[0]), "odoo.py")
447-
nargs = [cmd, 'gevent'] + nargs[1:]
448-
popen = subprocess.Popen([sys.executable] + nargs)
446+
cmd = [sys.executable, sys.argv[0], 'gevent'] + nargs[1:]
447+
popen = subprocess.Popen(cmd)
449448
self.long_polling_pid = popen.pid
450449

451450
def worker_pop(self, pid):

setup/setup_dev.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,7 @@ def main():
153153
elif len(sys.argv) == 2 and sys.argv[1] in cmds:
154154
cmds[sys.argv[1]]()
155155
else:
156-
if len(sys.argv) > 1 and sys.argv[1] == 'gevent':
157-
sys.argv.remove('gevent')
158-
import gevent.monkey
159-
gevent.monkey.patch_all()
160-
import psycogreen.gevent
161-
psycogreen.gevent.patch_psycopg()
162-
import odoo
163-
odoo.cli.main()
156+
sys.exit('Unknow command. Command available: %r' % (cmds.keys(),))
164157

165158
if __name__ == "__main__":
166159
main()

0 commit comments

Comments
 (0)