0

I am working with a python script that calls some multiprocessing code that doesn't work under windows. I'd like to simply test whether os.name == "nt" and produce a message saying the action isn't supported under windows, as the stack trace is cryptic and involves pickling.

Is there a conventional Exception for this condition? Didn't see one in the docs. To clarify, I am not asking how to tell whether I am windows. I believe the == test above is fine for that.

Eli S
  • 1,379
  • 4
  • 14
  • 35
  • That question title is extremely misleading. It makes it sound like you're running into an issue where you're trying to do something in Python that the OS is throwing an error for and saying it's unsupported. – Abion47 Feb 12 '19 at 18:13
  • 3
    Possible duplicate of [Python: What OS am I running on?](https://stackoverflow.com/questions/1854/python-what-os-am-i-running-on) – Green Cloak Guy Feb 12 '19 at 18:13
  • `if os.name == "nt": do_windows_thing(); else: do_other_os_thing()`??? – r.ook Feb 12 '19 at 18:15
  • In this case there is no do_windows_thing() unless it is to raise an Exception. The code accesses OS services that are not available in Windows. I was wondering if there is a standard Exception to throw in this case. – Eli S Feb 13 '19 at 20:01
  • @EliS `OSError`? – Bakuriu Feb 13 '19 at 20:11
  • Arghhh. Yes, I don't know how I missed it. Feel free to take credit. – Eli S Feb 14 '19 at 15:51

1 Answers1

0

I'd say NotImplementedError is the right exception here as in principle you can also implement Python multiprocessing under Windows, just may require quite a bit of additional code and probably some changes to existing code. You can add a message for the user:

if os.name == "nt":
    raise NotImplementedError('multiprocessing not supported on Windows')
Joachim Wagner
  • 860
  • 7
  • 16