Superskyyy commented on issue #9071: URL: https://github.com/apache/skywalking/issues/9071#issuecomment-1308948811
> ## Use case > [skywalking.apache.org/docs/skywalking-python/next/en/setup/faq/how-to-use-with-uwsgi](https://skywalking.apache.org/docs/skywalking-python/next/en/setup/faq/how-to-use-with-uwsgi/) But start the application by cli as showd below > > ``` > sw-python uwsgi --die-on-term \ > --http 0.0.0.0:5000 \ > --http-manage-expect \ > --master --workers 3 \ > --enable-threads \ > --threads 3 \ > --manage-script-name \ > --mount /=main:app > ``` > > ## Potential cause > I've done a small amount of research, and this might be caused by the inherent property of Linux's `fork`. In Python Agent, we use a global variable [_started](https://github.com/apache/skywalking-python/blob/11a74be39b07d55290c2df3de2b499bb126de048/skywalking/agent/__init__.py#L39) to prevent redundant initialization. > > In `preforking mode` of `uWsgi`, > > 1. At first, `uWsgi` spawns a master process in which the Agent will be initialized for the first time and `_started` will be set as `True`. > 2. Then the master process spawns n worker processes in which `_started` remains `True`. So the necessary reporting threads will not be created here and nothing will be sent to `oap`. > > Commenting this [line](https://github.com/apache/skywalking-python/blob/11a74be39b07d55290c2df3de2b499bb126de048/skywalking/bootstrap/loader/sitecustomize.py#L147) preventing initialization inside the master process, then each worker processes will have its own Agent initialized successfully. Thank you, I see where the problem is, maybe adding PID info to the `__started` flag so upon fork we can allow a safe restart. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
