python - Starmap modifying a parameter before passing it in? -


I have a weird bug that is confronting me trying to use multi-processing. The minimum code required to reproduce the Pool.starmap bug is here:

  from Multiprocessing Import Pool # The fact is that this class is useless but do not pay attention, this is more code but This was not relevant for this: Bug class coordinates (Tupal): def __new __ (CLS, * Args): Returning Tuple .__ New__ (CLS, AGR) # accidentally stores only two coordinate classes: def __init__ ( self, oldPos, newPos): self.oldPos = oldPos self. New POS = New Peace DF __str __ (Self): Returns 'Old Position:' + (str.old.pos) + '- New Position:' + str (self.newPos) # Dummy function to show the problem Problem def FuncThatNeedsTwoParam (trick, (parameter): On the other hand the ultimate ignored, there is no problem p = pool (2) transfers (0, 2), coordinates (0, 1) coordinates (0, 1) moveTwo = move (2, 1) coordinate (3, 0)) move = move (coordinates (22345, -12400), coordinates (153, 2357)) numbers are irrelevant, There is no effect whether the problem appears or not = [move, move, move] ParamsForStarmap = [[move, second most] move in the move] Print (ParametersFormatarmp) #Output: # [[0x1023d4438] ;, 0x1023d4438] on the object, [& lt; __ Main __. Move object to 0x1023d4470>, 'Other Ultimate'], [& lt; __ Main__ . Remove object on 0x1023d44a8 & gt; For consultation in paramarsesa [Param [0] to go: print (moved) # Output: # Old position: (0, 2) - New position: (0, 1) # Old position: (2, 1) - - New position: (3, 0) # Old position: (22345, -12400) - New position: (153, 2357) p. Stormp (FunkTatNews, two Param, Parameters ForemostMap) #Output: #Old Position: ((0, 2)) - New Position: ((0, 1),) # Old Position: ((22345, -12400)) - New position: ((153, 2357),) # Old position: ((2, 1), - New position: ((3, 0),) Actually, I have There is a pair of parameters, something like: [[move, other paragraph], [step, other paragraph], ...], I print every first parameter to show that the moves before using the Storm Function Are valid. So I call the starmap function using the pool I created, and ask to use a couple of parameters I have described. Then, as the coordinates of each move, the form (co-ordinates) of the form becomes toplevels. Instead of (coordination).  

I can not know how the strumpet will change the properties of an object Thanks, thanks any help would be appreciated, thanks.

This is an interesting thing. This issue is not just with starmap , it happens with all the pool functions - application , map , etc. And, as it turns out, the problem is not with multiprocessing This happens exactly when you pickle / unplug the coordinate class: < Pre> gt; & Gt; C = coordinates (0,2) >> gt; & Gt; & Gt; Print (C) (0, 2) & gt; & Gt; & Gt; Str (pickle.loads (pickle.dumps (c))) '((0, 2))'

do not like to create a toplex subclass Appear as straightforward, it turns. You can fix by defining the method that fixes the salting process:

  class coordinates (tubal): def __new __ (cls, * args): return tube .__ new __ (CLS, AGR) def __reduce__ (self): return (self .__ class__, tupl (self)) Now it's just pickle:  
  & Gt; & Gt; & Gt; C = coordinates (0,2) >> gt; & Gt; & Gt; Pickle.loads (pickle.dumps (c)) (0, 2)   

and your example code works well.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -