jpy-consortium / jpy

Apache License 2.0
74 stars 18 forks source link

SIGSEGV when using `asyncio` and `yfinance` #148

Open jjbrosnan opened 6 months ago

jjbrosnan commented 6 months ago

The following code block works, or at least does not crash (it can give a 401 unauthorized HTML response) when run in Python alone. When run from inside of a JVM via jpy, it causes a SIGSEGV and subsequent crash.

I suspect asyncio is the culprit, however, I have successfully run asyncio code from within a JVM previously, so I'm not 100% sure.

import os
os.system('pip install yfinance')

import asyncio
import yfinance as yf

tickers = ['TSLA']

async def main():
    order_count = 1

    for _ in range(order_count):

        for ticker in tickers:
            underlying_stock = yf.Ticker(ticker)
            print(underlying_stock.info)

if __name__ == '__main__':
    asyncio.run(main())
    pass
chipkent commented 6 months ago

On the demo,

This kills the process:

import os
os.system('pip install yfinance')

import asyncio
import yfinance as yf

tickers = ['TSLA']

async def main():
    order_count = 1

    for _ in range(order_count):

        for ticker in tickers:
            underlying_stock = yf.Ticker(ticker)
            print(underlying_stock.info)

asyncio.run(main())

This also killed the worker:

import os
os.system('pip install yfinance')

import asyncio
import yfinance as yf

tickers = ['TSLA']

def main():
    order_count = 1

    for _ in range(order_count):

        for ticker in tickers:
            underlying_stock = yf.Ticker(ticker)
            print(underlying_stock.info)

main()