Author zmedico
Recipients Adam.Bishop, Christian H, christian.heimes, martius, neologix, pitrou, vstinner, yselivanov, zmedico
Date 2018-03-04.00:16:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520122604.28.0.467229070634.issue21998@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure about possible use cases that might conflict with this approach, but using a separate event loop for each pid seems very reasonable to me, as follows:

_default_policy = asyncio.get_event_loop_policy()
_pid_loop = {}

class MultiprocessingPolicy(asyncio.AbstractEventLoopPolicy):
	def get_event_loop(self):
		pid = os.getpid()
		loop = _pid_loop.get(pid)
		if loop is None:
			loop = self.new_event_loop()
			_pid_loop[pid] = loop
		return loop

	def new_event_loop(self):
		return _default_policy.new_event_loop()

asyncio.set_event_loop_policy(MultiprocessingPolicy())
History
Date User Action Args
2018-03-04 00:16:44zmedicosetrecipients: + zmedico, pitrou, vstinner, christian.heimes, neologix, yselivanov, Adam.Bishop, martius, Christian H
2018-03-04 00:16:44zmedicosetmessageid: <1520122604.28.0.467229070634.issue21998@psf.upfronthosting.co.za>
2018-03-04 00:16:44zmedicolinkissue21998 messages
2018-03-04 00:16:44zmedicocreate