code_interpreter_init_kernel.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import json # noqa
  2. import math # noqa
  3. import os # noqa
  4. import re # noqa
  5. import signal
  6. import matplotlib # noqa
  7. import matplotlib.pyplot as plt
  8. import numpy as np # noqa
  9. import pandas as pd # noqa
  10. import seaborn as sns
  11. from matplotlib.font_manager import FontProperties
  12. from sympy import Eq, solve, symbols # noqa
  13. def input(*args, **kwargs):
  14. raise NotImplementedError('Python input() function is disabled.')
  15. def _m6_timout_handler(_signum=None, _frame=None):
  16. raise TimeoutError('M6_CODE_INTERPRETER_TIMEOUT')
  17. try:
  18. signal.signal(signal.SIGALRM, _m6_timout_handler)
  19. except AttributeError: # windows
  20. pass
  21. class _M6CountdownTimer:
  22. @classmethod
  23. def start(cls, timeout: int):
  24. try:
  25. signal.alarm(timeout)
  26. except AttributeError: # windows
  27. pass # TODO: I haven't found a solution that works with jupyter yet.
  28. @classmethod
  29. def cancel(cls):
  30. try:
  31. signal.alarm(0)
  32. except AttributeError: # windows
  33. pass # TODO
  34. sns.set_theme()
  35. _m6_font_prop = FontProperties(fname='{{M6_FONT_PATH}}')
  36. plt.rcParams['font.family'] = _m6_font_prop.get_name()