From febc303acd32c9acf2aa967171b86beb3d849173 Mon Sep 17 00:00:00 2001 From: cocolato Date: Thu, 18 Apr 2024 23:05:08 +0800 Subject: [PATCH 1/7] support mp spawn mode --- setup.py | 1 + tests/test_all_protocols_binary_field.py | 11 ++++++++--- tox.ini | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index ab45325..238767f 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,7 @@ "sphinx-rtd-theme>=0.1.9", "sphinx>=1.3", "pytest>=6.1.1", + "multiprocess" ] + tornado_requires diff --git a/tests/test_all_protocols_binary_field.py b/tests/test_all_protocols_binary_field.py index e75e141..8ddf6a5 100644 --- a/tests/test_all_protocols_binary_field.py +++ b/tests/test_all_protocols_binary_field.py @@ -3,7 +3,7 @@ import sys import time import traceback -from multiprocessing import Process +from multiprocess import Process import pytest import six @@ -26,8 +26,8 @@ from thriftpy2.transport import TBufferedTransportFactory, TCyMemoryBuffer -if sys.platform == "win32": - pytest.skip("requires fork", allow_module_level=True) +# if sys.platform == "win32": +# pytest.skip("requires fork", allow_module_level=True) protocols = [TApacheJSONProtocolFactory, @@ -72,6 +72,11 @@ def test(t): trans_factory = TBufferedTransportFactory def run_server(): + import thriftpy2 + test_thrift = thriftpy2.load( + "apache_json_test.thrift", + module_name="test_thrift" + ) server = server_func[0]( test_thrift.TestService, handler=Handler(), diff --git a/tox.ini b/tox.ini index 1acd731..b24d3c6 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ deps = tornado>=4.0,<6.0 cython py35,py36,py37,py38,py39,pypy3,coverage: pytest_asyncio + multiprocess [testenv:flake8] deps = From 1042bc6d74110bdaf97228f7db132af7a69cced2 Mon Sep 17 00:00:00 2001 From: cocolato Date: Thu, 18 Apr 2024 23:27:20 +0800 Subject: [PATCH 2/7] support mp spawn mode --- tests/test_all_protocols_binary_field.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_all_protocols_binary_field.py b/tests/test_all_protocols_binary_field.py index 8ddf6a5..df25df8 100644 --- a/tests/test_all_protocols_binary_field.py +++ b/tests/test_all_protocols_binary_field.py @@ -26,8 +26,6 @@ from thriftpy2.transport import TBufferedTransportFactory, TCyMemoryBuffer -# if sys.platform == "win32": -# pytest.skip("requires fork", allow_module_level=True) protocols = [TApacheJSONProtocolFactory, @@ -166,11 +164,16 @@ def test_exceptions(server_func, proto_factory): ) TestException = test_thrift.TestException - class Handler(object): - def do_error(self, arg): - raise TestException(message=arg) - def do_server(): + import thriftpy2 + test_thrift = thriftpy2.load( + "apache_json_test.thrift", + module_name="test_thrift" + ) + TestException = test_thrift.TestException + class Handler(object): + def do_error(self, arg): + raise TestException(message=arg) server = server_func[0]( service=test_thrift.TestService, handler=Handler(), @@ -242,6 +245,8 @@ def test(t): trans_factory = TBufferedTransportFactory def run_server(): + import thriftpy2 + spec = thriftpy2.load("bin_test.thrift", module_name="bin_thrift") server = make_rpc_server( spec.BinService, handler=Handler(), From 72eb4673da2a9a6b09eceed48aa59a8f0c271148 Mon Sep 17 00:00:00 2001 From: cocolato Date: Mon, 15 Jul 2024 21:55:19 +0800 Subject: [PATCH 3/7] update dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index cbf07d3..c46036c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dev = [ "pytest>=6.1.1,<8.2.0", "tornado>=4.0,<7.0; python_version>='3.12'", "tornado>=4.0,<6.0; python_version<'3.12'", + "multiprocess>=0.70.12.2", ] tornado = [ From 000bcbae6dbb7755fa3050c4ef3a2d438adfb52d Mon Sep 17 00:00:00 2001 From: cocolato Date: Mon, 15 Jul 2024 22:09:22 +0800 Subject: [PATCH 4/7] remove skip on windows --- tests/test_http.py | 9 ++------- tests/test_multiplexed.py | 9 ++------- tests/test_oneway.py | 8 ++------ tests/test_tracking.py | 11 +++-------- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/tests/test_http.py b/tests/test_http.py index 6d7493a..e5ac0e4 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -3,9 +3,8 @@ from __future__ import absolute_import import os -import multiprocessing +import multiprocess import socket -import sys import time import uuid @@ -22,10 +21,6 @@ "addressbook.thrift")) -if sys.platform == "win32": - pytest.skip("requires fork", allow_module_level=True) - - class Dispatcher(): def __init__(self): self.ab = addressbook.AddressBook() @@ -81,7 +76,7 @@ def get_headers(self): def server(request): server = make_server(addressbook.AddressBookService, Dispatcher(), host="127.0.0.1", port=6080) - ps = multiprocessing.Process(target=server.serve) + ps = multiprocess.Process(target=server.serve) ps.start() time.sleep(0.1) diff --git a/tests/test_multiplexed.py b/tests/test_multiplexed.py index 3f38abf..9d62c59 100644 --- a/tests/test_multiplexed.py +++ b/tests/test_multiplexed.py @@ -2,9 +2,8 @@ from __future__ import absolute_import -import multiprocessing +import multiprocess import os -import sys import time import pytest @@ -20,10 +19,6 @@ from thriftpy2.transport import TBufferedTransportFactory, TServerSocket -if sys.platform == "win32": - pytest.skip("requires fork", allow_module_level=True) - - mux = thriftpy2.load(os.path.join(os.path.dirname(__file__), "multiplexed.thrift")) sock_path = "/tmp/thriftpy_test.sock" @@ -51,7 +46,7 @@ def server(request): _server = TThreadedServer(mux_proc, TServerSocket(unix_socket=sock_path), iprot_factory=TBinaryProtocolFactory(), itrans_factory=TBufferedTransportFactory()) - ps = multiprocessing.Process(target=_server.serve) + ps = multiprocess.Process(target=_server.serve) ps.start() time.sleep(0.1) diff --git a/tests/test_oneway.py b/tests/test_oneway.py index fcf88ba..a70f413 100644 --- a/tests/test_oneway.py +++ b/tests/test_oneway.py @@ -3,15 +3,11 @@ import pytest -import multiprocessing +import multiprocess import thriftpy2 from thriftpy2.rpc import make_client, make_server -if sys.platform == "win32": - pytest.skip("requires fork", allow_module_level=True) - - class Dispatcher(object): def Test(self, req): print("Get req msg: %s" % req) @@ -24,7 +20,7 @@ class TestOneway(object): oneway_thrift = thriftpy2.load("oneway.thrift") def setup_class(self): - ctx = multiprocessing.get_context("fork") + ctx = multiprocess.get_context("fork") server = make_server(self.oneway_thrift.echo, Dispatcher(), '127.0.0.1', 6000) self.p = ctx.Process(target=server.serve) self.p.start() diff --git a/tests/test_tracking.py b/tests/test_tracking.py index 9d71d4d..a971379 100644 --- a/tests/test_tracking.py +++ b/tests/test_tracking.py @@ -18,12 +18,11 @@ from __future__ import absolute_import import contextlib -import multiprocessing +import multiprocess import os import pickle import random import socket -import sys import tempfile import time @@ -56,11 +55,7 @@ except ImportError: pass else: - cleanup_on_sigterm() - - -if sys.platform == "win32": - pytest.skip("requires fork", allow_module_level=True) + cleanup_on_sigterm() addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__), @@ -191,7 +186,7 @@ def gen_server(port, tracker=tracker, processor=TTrackedProcessor): server = TSampleServer(processor, server_socket, prot_factory=TBinaryProtocolFactory(), trans_factory=TBufferedTransportFactory()) - ps = multiprocessing.Process(target=server.serve) + ps = multiprocess.Process(target=server.serve) ps.start() return ps, server From 07037f899ae8e11d6c42bbabbd058576b3fe1fe5 Mon Sep 17 00:00:00 2001 From: cocolato Date: Mon, 15 Jul 2024 22:29:40 +0800 Subject: [PATCH 5/7] remove skip on windows --- tests/test_oneway.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_oneway.py b/tests/test_oneway.py index a70f413..c33658f 100644 --- a/tests/test_oneway.py +++ b/tests/test_oneway.py @@ -20,9 +20,8 @@ class TestOneway(object): oneway_thrift = thriftpy2.load("oneway.thrift") def setup_class(self): - ctx = multiprocess.get_context("fork") server = make_server(self.oneway_thrift.echo, Dispatcher(), '127.0.0.1', 6000) - self.p = ctx.Process(target=server.serve) + self.p = multiprocess.Process(target=server.serve) self.p.start() time.sleep(1) # Wait a second for server to start. From d67543175f730b3ec1bf39f0faf21b8bb0591f38 Mon Sep 17 00:00:00 2001 From: cocolato Date: Mon, 15 Jul 2024 22:52:04 +0800 Subject: [PATCH 6/7] remove skip on windows --- tests/test_http.py | 3 +++ tests/test_multiplexed.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_http.py b/tests/test_http.py index e5ac0e4..a9bc7a2 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -74,6 +74,9 @@ def get_headers(self): @pytest.fixture(scope="module") def server(request): + import thriftpy2 + addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__), + "addressbook.thrift")) server = make_server(addressbook.AddressBookService, Dispatcher(), host="127.0.0.1", port=6080) ps = multiprocess.Process(target=server.serve) diff --git a/tests/test_multiplexed.py b/tests/test_multiplexed.py index 9d62c59..335a21f 100644 --- a/tests/test_multiplexed.py +++ b/tests/test_multiplexed.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +import sys import multiprocess import os @@ -77,7 +78,7 @@ def client_two(timeout=3000): socket_timeout=timeout, connect_timeout=timeout, proto_factory=multiplexing_factory) - +@pytest.mark.skipif(sys.platform == "win32", "requires socket.UNIX") def test_multiplexed_server(server): with client_one() as c: assert c.doThingOne() is True From af8a4bb866db9c4088e70c9e6b5c070f955ab84d Mon Sep 17 00:00:00 2001 From: cocolato Date: Mon, 15 Jul 2024 22:57:00 +0800 Subject: [PATCH 7/7] remove skip on windows --- tests/test_multiplexed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_multiplexed.py b/tests/test_multiplexed.py index 335a21f..7a2a8b0 100644 --- a/tests/test_multiplexed.py +++ b/tests/test_multiplexed.py @@ -78,7 +78,7 @@ def client_two(timeout=3000): socket_timeout=timeout, connect_timeout=timeout, proto_factory=multiplexing_factory) -@pytest.mark.skipif(sys.platform == "win32", "requires socket.UNIX") +@pytest.mark.skipif(sys.platform == "win32", reason="Unix domain socket required") def test_multiplexed_server(server): with client_one() as c: assert c.doThingOne() is True