I know the OP was directed at what women think but to add another male voice. It all depends on the relationship and if the female partner has said she doesn’t like it or the idea of it, for any number of reasons, it then he should refrain from doing it, go to another room etc. Although in our house there would be more chance of me waking up DW getting up to go to another room, then coming back, than masturbating beside her; and some people may not have the luxury of another room, kids, etc.
Men get several erections during the night, probably aren’t aware of most of them, and usually wake up with one; quite often accompanied by the need for a pee, a bladder-hard. And if they do wake up the erection will usually subside in seconds. But, sometimes you just wake up to a stonking erection and feeling horny, possibly accompanied by a fruity dream or thoughts, and it just ain’t going away.
The frequency is gradually decreasing now (it’s a bugger getting old!) but in the past possibly once a month or so I would get this. If DW was awake or half-awake I would start some touchy-feely and hopefully get some action, or if she woke part-way through she would lend a hand, but if not I perfected a technique to stimulate my penis and ejaculate without rocking the bed. The sticky tissues on the floor next to the bed would give the game away next morning and we would exchange some saucy banter. My DW doesn’t have a problem but if anyone doesn't like it then yes the DH/DP should comply with her wishes.