#๐Ÿ”’ multiprocessing Event type hint

17 messages ยท Page 1 of 1 (latest)

fluid sun
#

I'm trying to properly type hint this argument but Pylance is getting upset at it being a variable. I'm using the multiprocessing library built into Python. What is the correct way to do this type hint?

harsh deltaBOT
#

@fluid sun

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fluid sun
#
from multiprocessing import Event, Process

its imported like this

arctic plover
fluid sun
#
def start_frida_server(event: Event) -> None:
    """..."""

function is just barebones rn, what do you want to see specifically?

#
    Process(
        target=start_frida_server,
        args=(event,),
    ).start()

its called like this

event = Event()

with event being defined like this

steep pond
#

you can try something like

from multiprocessing.synchronize import Event as EventClass
``` that's where the class is
#

the normal import points to Event = context._default_context.Event

#

that's why it's a "variable"

fluid sun
#

that worked, and also fixed pylance not being able to figure out the methods. thank you!

steep pond
#

just keep in mind that when you import Event the first way, it gets initialised via

    def Event(self):
        '''Returns an event object'''
        from .synchronize import Event
        return Event(ctx=self.get_context())
``` I'm not sure why, so I would avoid doing `from multiprocessing.synchronize import Event` as a replacement for the initial import
fluid sun
#

yea it doesnt work properly if i replace the whole thing

#

so i just imported both ,one to use, one to hint

steep pond
#

sounds good

forest radish
#

Just for the exercise I went:

>>> from multiprocessing import Event
>>> type(Event)
<class 'method'>

It's not a type.

harsh deltaBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.